[Haskell-cafe] Either example

Alvaro Gutierrez radical at google.com
Thu Feb 7 05:04:24 CET 2013


Often, Either is used to represent, exclusively, a value or a failure, in a
more detailed way than Maybe can. For example, a function like `parse` (
http://hackage.haskell.org/packages/archive/parsec/latest/doc/html/Text-Parsec-Prim.html#v:parse),
which is part of Parsec, might have a type like:

parse :: [...] s ->
Either<http://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/Data-Either.html#t:Either>
 ParseError<http://hackage.haskell.org/packages/archive/parsec/latest/doc/html/Text-Parsec-Error.html#t:ParseError>
 a

Meaning, parsing will either fail with a Left ParseError, or succeed with a
Right a, where a is whatever type your parser returns.

Hope that helps,

Alvaro





On Wed, Feb 6, 2013 at 9:37 PM, Jacob Thomas <jthomas7 at ucsc.edu> wrote:

>
> Hello
>
> I'm new to Haskell, and need help with figuring out the Either type...
> Any example to show how this works?
>
> Jacob
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130206/26ac9fd7/attachment.htm>


More information about the Haskell-Cafe mailing list