我正在尝试为多态树类型定义显示函数。任何人都可以帮我吗?多态类型的显示函数
import Char
data Tree t =
NilT |
Node t (Tree t) (Tree t)
class Mar t where
maior :: t -> String
instance Mar Tree where
maior (NilT) = "a"
maior (Node t a b) = "b"
instance Show Tree where
show = maior
非常感谢!
溶液(ivanm给出):
import Char
data Tree t =
NilT |
Node t (Tree t) (Tree t)
class Mar t where
maior :: t -> String
instance Mar (Tree t) where
maior (NilT) = "a"
maior (Node t a b) = "b"
instance Show (Tree t) where
show = maior
感谢拍摄,但它仍然给我同样的错误(你提到的那个)=/ – Filipe
我的坏,它工作!非常感谢!!! – Filipe