[Haskell-beginners] Maybe, Either

Yusaku Hashimoto nonowarn at gmail.com
Sat Sep 12 11:51:56 EDT 2009


I think there is no such function in standard library.

But you can also do the same by `maybe (Left err) Right (lookup key
assoc)` without defining eitherLookup.

HTH
-nwn

On Sun, Sep 13, 2009 at 12:14 AM, Michael Mossey <mpm at alumni.caltech.edu> wrote:
> I want to use 'lookup' inside an Either String monad. So I want to write
> something like
>
> eitherLookup :: Eq a => String -> a -> [(a,b)] -> Either String b
> eitherLookup s x ps = case lookup x ps of
>                         Just y -> Right y
>                         Nothing -> Left s
>
> Is there such a function existing?
>
> Thanks,
> Mike
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>


More information about the Beginners mailing list