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.