1
は下記考えてみましょう:明示的にクラスメソッドの戻り値の型を指定していますか?
class Test m a where
t :: Int -> m a
instance Test [] Int where
t i = [i]
instance Test Maybe Int where
t i | i == 0 = Nothing
| otherwise = Just i
main = do
print $ t (22 :: Int) --Error!
これは、次のエラーでスローされます。
Ambiguous type variables ‘m0’, ‘a0’ arising from a use of ‘print’
prevents the constraint ‘(Show (m0 a0))’ from being solved.
これは、コンパイラがm a
のどのインスタンスに使用する特定の方法がないためです。どのように私はこれを明示することができますか?