[Haskell-cafe] Convert Either to Tree - Occurs check

André Batista Martins andre_bm at netcabo.pt
Fri Oct 22 07:08:16 EDT 2010


Tks for the answser,
I need to continue a work that has already been developed. In this work i
have  Eithers and i want convert  to another datatype with more information,
because I want to generate  Eithers, which will contain the information from
the first but with positions exchanged.

No dia 22 de Outubro de 2010 11:30, Neil Brown <nccb2 at kent.ac.uk> escreveu:

>  On 22/10/10 09:23, André Batista Martins wrote:
>
> Tks for the answer,
> the data structure of Either is:
>
>
> data  Either a b  =  Left a | Right b   deriving (Eq, Ord, Read, Show)
>
>
> one example of what i want convert is:
>  Left(Right(Left(Left())))
>
>  Hi,
>
> The problem here is that the type of Left () is:
>
> > Either () a
>
> The type of Left (Left ()) is:
>
> > Either (Either () a) b
>
> The type of Right (Left (Left ())) is:
>
> > Either c (Either (Either () a) b)
>
> and finally, the type of Left (Right (Left (Left ()))) is:
>
> > Either (Either c (Either (Either () a) b)) d
>
> That is, each level in the tree must have a different type.  For this
> reason, you can't sensibly use Either for tree types of varying depth (a
> type-class would help, but I doubt it's what you want).  A sensible type for
> a tree is the one you gave in your original post, TreeE.  So why do you want
> to encode the tree with Either (not really possible) and then convert to
> your TreeE type?  Why not just start out with the values in your tree type?
>
> Thanks,
>
> Neil.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20101022/cab51d03/attachment.html


More information about the Haskell-Cafe mailing list