我尝试在haskell中创建自己的列表类型,但是,我的实现包含错误。 什么是正确的方法来做到这一点很好。请给我解释一下。 谢谢。我的列表输入haskell
我的代码:
data List a = EmptyList | ListElement a (List a)
instance (Show a) => Show (List a) where
show = showList'
showList' EmptyList = showString "[]"
showList' (ListElement a EmptyList) = show a
showList' (ListElement a b) = show a ++ show " " ++ showList' b
错误代码:
[1 of 1] Compiling Main (tipusok.hs, interpreted)
tipusok.hs:12:39:
Couldn't match expected type `Prelude.String -> Prelude.String'
with actual type `[Char]'
Expected type: ShowS
Actual type: Prelude.String
In the return type of a call of `show'
In the expression: show a
Failed, modules loaded: none.
:)它的工作,谢谢你 – flatronka