-1
\$\begingroup\$

Given [1,2,3], I wrote the following to get [[1],[2],[3]]:

ghci> map return [1,2,3] :: [[Int]]
[[1],[2],[3]]

Is this usage of return idiomatic in Haskell? I'm asking since I could've also used pure instead.

\$\endgroup\$
5
\$\begingroup\$

I don't see any problem with this. I guess the question could be one of declaring your intent to your reader:

by using return, you very much tell the reader that you are going to work with the list monad;

by using pure you would make them understand your decision in terms of applicative;

by using (:[]), they would simply think that you want to turn a list into a list of singletons.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.