Monad Wars - 2: the command line

Comments

but which monad is it in, and more to the point, why?
Any monad you want, and flexibility. If the lookup finds the key, it returns the corresponding value packaged up in that monad, otherwise it fails. What "failure" means depends on the monad. In IO, it throws an exception. In List, it's an empty list... and in Maybe, it's Nothing — which is exactly what you want!. So you could define parseMap as, simply:
parseMap :: Ord k => M.Map k a -> k -> Maybe a
parseMap2 = flip M.lookup
Clever, eh?
Oops, uh,, I don't know where that "2" on "parseMap2" came from.
[this is good]
Thanks! I've written up some notes after this and other comments in a top-level post: http://osfameron.vox.com/library/post/monad-wars---25-some-comments-and-corrections.html

Post a comment

Already a Vox member? Sign in