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.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe