class FooAble t where
foo :: t->Bool
foo _ = False
instance FooAble Int where
foo x | x == 3 = True
| otherwise = False
при попытке выполнить foo 3 появляется ошибка:
*Nat> foo 3
<interactive>:113:1:
No instance for (FooAble t0) arising from a use of `foo'
The type variable `t0' is ambiguous
Note: there is a potential instance available:
instance FooAble Int -- Defined at Nat.hs:75:10
In the expression: foo 3
In an equation for `it': it = foo 3
<interactive>:113:5:
No instance for (Num t0) arising from the literal `3'
The type variable `t0' is ambiguous
Note: there are several potential instances:
instance Integral a => Num (GHC.Real.Ratio a)
-- Defined in `GHC.Real'
instance Num Integer -- Defined in `GHC.Num'
instance Num Double -- Defined in `GHC.Float'
...plus three others
In the first argument of `foo', namely `3'
In the expression: foo 3
In an equation for `it': it = foo 3
*Nat>
как справиться с ошибкой? написание (fromInteger 3) и там и там не помогает
и еще такой вопрос: могу ли я в области сопоставления с образцом писать
foo 3 = ...
foo (fromInteger 3) = ...