1

私は持っています

data Dictionary a = Empty
                  | Branch (a, Bool, Dictionary a) (Dictionary a)
                  deriving (Ord, Eq)

instance Show (Dictionary a) where show = showDict

showDict (Branch (val, e, dict) dict2) = "My dict is : " ++ val 

私はそれが間違いなく間違っていることを知っていますが、これを書く方法を見つけることができませんでした。showDict関数では、valの型はですが、期待される型は[Char]です。

前もって感謝します。

4

2 に答える 2

5

val文字列に変換するには、次のようにしますshow

showDict (Branch (val, e, dict) dict2) = "My dict is : " ++ show val

そして、次の型の制約を忘れないでくださいshowDict

instance Show a => Show (Dictionary a) where show = showDict
于 2012-04-10T08:48:48.247 に答える
1

instance(Show a)=> Show(Dictionary a)where show = showDict

はshowable型クラスに属していることを伝える必要があります。そうでない場合、showonvalを使用できません。

于 2012-04-10T11:07:20.710 に答える