Take the 2-minute tour ×

Looking for a built-in function that will do the following:

mklist x = [x]

The benefit is that I can use it in a composition to create a list of one element. Understand that (replicate 1) is available but is there a more direct function? Would be useful in situations like this:

["Alice", "Bob", "Charlie"] >>= mklist . ("Hello " ++)
share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

Monadic return:

return x


(:[]) x

It's less characters, but more shift-key usage, so might be harder to type.

share|improve this answer
Oh. Right. Duh. Thanks. –  me2 Feb 3 '10 at 9:09
:-) Of course your example could just as easily be done using map, but I'm assuming your real scenario is more complex. –  Tom Lokhorst Feb 3 '10 at 9:11
pure from Control.Applicative also works. That's four non-shifted letters! As with return any type errors may get more complicated, though. –  yatima2975 Feb 3 '10 at 11:33
Yeah, it's a shame pure isn't in the Prelude, though. But if you do have Control.Applicative imported anyway, then pure is nice and short, just like we Haskell programmers like. –  Tom Lokhorst Feb 3 '10 at 12:44
Ooh, monadic return. +1 for sneakiness and code obfuscation! –  Norman Ramsey Feb 4 '10 at 0:38
add comment

In case you're not familiar with hoogle:


share|improve this answer
add comment

Your Answer


