试图找出 Haskell 类型类。为什么以下不起作用?
{-# LANGUAGE FlexibleInstances #-}
class IntClass t
instance IntClass Int
intToIntClass :: (IntClass r) => Int -> r
intToIntClass x = x
显然,“实例”并不意味着我认为它应该意味着什么。相反,它给出了我不明白的错误消息。
Could not deduce (r ~ Int)
from the context (IntClass r)
bound by the type signature for intToIntClass :: IntClass r => Int -> r
at f.hs:10:1-16
`r' is a rigid type variable bound by
the type signature for intToIntClass :: IntClass r => Int -> r
at f.hs:10:1
In the expression: x
In an equation for `intToIntClass t': intToIntClass x = x