[Haskell-cafe] Re: Maybe to Either -- is there a better way?
tgdavies at gmail.com
Tue Aug 3 17:37:53 EDT 2010
On 03/08/2010, at 10:09 PM, Ertugrul Soeylemez wrote:
> Tom Davies <tgdavies at gmail.com> wrote:
>> I find it convenient sometimes to convert a Maybe value to an Either
>> thus (excuse the syntax, it's CAL, not Haskell):
>> maybeToEither :: a -> Maybe b -> Either a b;
>> maybeToEither errorValue = maybe (Left errorValue) (\x -> Right x);
> As a side note, this is perfectly valid Haskell code, even though it's
> quite verbose. The equivalent:
> maybeToEither :: a -> Maybe b -> Either a b
> maybeToEither leftValue = maybe (Left leftValue) Right
I like that better, and CAL supports that, thanks.
> Honestly I find this better than the completely points-free variants
> posted in the other subthread. They demonstrate overusing points-free
I agree -- as an inexperienced functional programmer, but not a complete beginner, I found the points free versions incomprehensible!
More information about the Haskell-Cafe