Haskell中的预期类型与实际类型错误

Haskell中的预期类型与实际类型错误,haskell,types,compiler-errors,functional-programming,Haskell,Types,Compiler Errors,Functional Programming,我在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 这个功能是: equilibre :: TreeRN a -> TreeRN a equilibre (No

我在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
这个功能是:

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))
这是我的问题:

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.
通常,当我遇到这种错误时,我理解为什么,并且我可以纠正我的函数,但是在这里,我对错误感到失望

Couldn't match expected type ‘TreeRN a’
            with actual type ‘Tree (Color, t3)’

虽然我声明的类型TreeRN是相同的(对我来说),所以我需要回答为什么编译器会说“t3”,这是什么意思?它与树(颜色,a)真的不同吗?

看起来您希望
TreeRN x
成为
Tree(颜色,x)
的同义词。我认为您刚刚使用了错误的关键字--
data
定义了一个新的代数数据类型。试一试

type TreeRN x = Tree (Color, x)

您还需要删除对类型同义词无效的
派生
子句。

多亏了您,我现在明白了,我承认我不知道数据和类型之间的区别。所以我没想过。