【发布时间】:2011-11-20 16:31:26
【问题描述】:
我正在尝试为多态树类型定义 Show 函数。谁能帮帮我?
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
【问题讨论】:
标签: haskell types tree polymorphism