Reputation: 81
I declared these types in Haskell :
data Tree x = Node x (Tree x) (Tree x)
|Leef
deriving Show
data Color = R | N
deriving (Show, Eq)
data TreeRN x = Tree (Color,x)
deriving Show
and this function :
equilibre :: TreeRN a -> TreeRN a
equilibre (Node (N,z) (Node (R,y) (Node (R,x) a b) c) d) = (Node (R,y) (Node (N,x) a b) (Node (N,z) c d))
equilibre (Node (N,z) (Node (R,x) a (Node (R,y) b c)) d) = (Node (R,y) (Node (N,x) a b) (Node (N,z) c d))
equilibre (Node (N,x) a (Node (R,z) (Node (R,y) b c) d)) = (Node (R,y) (Node (N,x) a b) (Node (N,z) c d))
equilibre (Node (N,x) a (Node (R,y) b (Node (R,z) c d))) = (Node (R,y) (Node (N,x) a b) (Node (N,z) c d))
And here is my issue :
Couldn't match expected type ‘TreeRN a’
with actual type ‘Tree (Color, t3)’
Relevant bindings include
d :: Tree (Color, t3) (bound at test.hs:15:53)
c :: Tree (Color, t3) (bound at test.hs:15:51)
z :: t3 (bound at test.hs:15:48)
b :: Tree (Color, t3) (bound at test.hs:15:37)
y :: t3 (bound at test.hs:15:34)
a :: Tree (Color, t3) (bound at test.hs:15:23)
equilibre :: TreeRN a -> TreeRN a (bound at test.hs:12:1)
(Some bindings suppressed; use -fmax-relevant-binds=N or -fno-max-relevant-binds)
In the expression:
(Node (R, y) (Node (N, x) a b) (Node (N, z) c d))
In an equation for ‘equilibre’:
equilibre (Node (N, x) a (Node (R, y) b (Node (R, z) c d)))
= (Node (R, y) (Node (N, x) a b) (Node (N, z) c d))
Failed, modules loaded: none.
Usually when I get this kind of error I understand why and I can correct my function, but here I am disappoint by the
Couldn't match expected type ‘TreeRN a’
with actual type ‘Tree (Color, t3)’
while my declared type TreeRN is the same (for me), so I need answer for why the compiler say 't3', what does it mean ? It is really different to Tree (Color,a) ?
Upvotes: 1
Views: 124
Reputation: 60463
It looks like you are expecting TreeRN x
to be a synonym for Tree (Color, x)
. I think you have just used the wrong keyword -- data
defines a new algebraic data type. Try
type TreeRN x = Tree (Color, x)
You will also need to remove the deriving
clause which is not valid for type synonyms.
Upvotes: 3