<br>hello,<br> i want convert "Either" to a tree.<br> Example:<br> Either ( Either 1 2 ) ( Either 3 4) ---- > Branch ( Branch (Leafl 1) (Leafr2) ) ( Branch (Leafl 3) (Leafr4)) ) <br>
<br> <br>Code: <br>data TreeE a b = Empty |Leafl a | Leafr b | Branch (TreeE a b ) (TreeE a b) deriving Show<br>
<br>f3 (Right b) (Branch l r) =case( isRight(b) || isLeft(b) )of<br> true -> Branch l (f3 b r)<br> false -> Branch l (Leafl b)<br>f3 (Left b) (Branch l r) = case( isRight(b) || isLeft(b) )of<br>
true -> Branch (f3 b l) r<br> false -> Branch (Leafl b) r<br><br>Error:<br> Occurs check: cannot construct the infinite type: b = Either a b<br> Expected type: Either a b -> TreeE t t1 -> TreeE t t1<br>
Inferred type: Either a (Either a b) -> TreeE t t1 -> t2<br> In the second argument of `Branch', namely `(f3 b r)'<br> In the expression: Branch l (f3 b r)<br><br>I don't understand why this happen...<br>
Can anyone help me?<br>