Hey Ranald, and welcome to the Cameralabs Forums!
To answer your question, all three of these lenses all have different purposes. The 35mm is a superb, small, compact and inexpensive lens that gives a 35mm equivalent of 50mm on a DX camera (such as your D3100) resulting in a "normal" field of view. It's a great lens for day to day shooting, both indoors and outside. I'd go for this lens if you want something that will function as an all-purpose prime.
The 50mm is also a nice, sharp prime that gives a 35mm equivalent of 75mm, meaning that it would be great for portrait work or everyday shooting. It's not as wide as the 35mm, so in some situations you may find yourself looking for the slightly wider field of view, but it's still a wonderful lens. I'd take a look at it if you're really interested in portraiture.
The new 40mm f/2.8 is more of a specialized lens, it's a small, general purpose micro (macro) lens for shots of flowers or other close up objects. It's a tad bit larger than the 35mm, but a full 1 1/3 stop slower, so you do lost a fair bit of light. It gives a 60mm equivalent, so it's somewhere between the 50mm and 75mm that the other two offer. The fact that it doubles as an "everyday" lens plus a macro lens is a great reason to consider it, but you'll have to deal with the loss of light. I'd purchase this lens if you want a prime that will work in most situations, plus double as a macro lens.
You can read more about it in my post here