为什么以下编译:
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverlappingInstances #-}
class IsList a where
isList :: a -> Bool
instance IsList a where
isList x = False
instance IsList [a] where
isList x = True
main = print (isList 'a') >> print (isList ['a'])
但main
改成这样:
main = print (isList 42) >> print (isList [42])
给出以下错误:
Ambiguous type variable `a0' in the constraints:
(Num a0) arising from the literal `42' at prog.hs:13:22-23
(IsList a0) arising from a use of `isList' at prog.hs:13:15-20
Probable fix: add a type signature that fixes these type variable(s)
In the first argument of `isList', namely `42'
In the first argument of `print', namely `(isList 42)'
In the first argument of `(>>)', namely `print (isList 42)'
isList
肯定不在Num
课堂上吧?如果不是,为什么会模棱两可?