これが私のコードです:
test :: (Num a) => [a] -> a
test [] = 0
test [x:xs] = x + test xs
しかし、ghci as:l test
で実行すると、次のエラーが発生します。
[1/1] Main のコンパイル ( test.hs、解釈済み )
test.hs:3:7:
Couldn't match type `a' with `[a]'
`a' is a rigid type variable bound by
the type signature for spew :: Num a => [a] -> a at test.hs:2:1
In the pattern: x : xs
In the pattern: [x : xs]
In an equation for `spew': spew [x : xs] = x + spew xs
Failed, modules loaded: none.
笑わないように気をつけてください :) Haskell での私の最初の試みです。どんな助けや説明も素晴らしいでしょう。
PS: これは折り畳みで簡単にできることはわかっていますが、独自の型シグネチャを書く練習をしようとしています。前もって感謝します!!