[Haskell-cafe] Convert Either to Tree - Occurs check
Neil Brown
nccb2 at kent.ac.uk
Fri Oct 22 06:30:42 EDT 2010
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/fc34579a/attachment.html
More information about the Haskell-Cafe
mailing list