我正在尝试编写一个返回列表中第一项的 Haskell 函数。
h [] = Nothing
h (x:xs) = x
当我用空列表调用它时:
main = print (h [])
我收到以下错误:
prog.hs:4:8:
No instance for (Show a0) arising from a use of `print'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Show Double -- Defined in `GHC.Float'
instance Show Float -- Defined in `GHC.Float'
instance (Integral a, Show a) => Show (GHC.Real.Ratio a)
-- Defined in `GHC.Real'
...plus 23 others
In the expression: print (h [])
In an equation for `main': main = print (h [])
当我为函数提供空列表时,我希望结果为Nothing 。