[Haskell-beginners] error monad and Map lookup

Brandon Allbery allbery.b at gmail.com
Thu Dec 22 21:04:19 CET 2011


On Thu, Dec 22, 2011 at 14:44, Dennis Raddle <dennis.raddle at gmail.com>wrote:

> test :: Int -> Either String String
> test x = do
>   y <- case M.lookup x testMap of
>          Nothing -> throwError "not in map"
>          Just z -> return z
>   return y
>

> test x = maybe (Left "not in map") Right $ M.lookup x testMap

-- 
brandon s allbery                                      allbery.b at gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111222/c9f7107e/attachment.htm>


More information about the Beginners mailing list