(решил ещё и тут спросить. На #haskell меня что-то проигнорировали.)
Вот код:
module A2 where
import Data.Data
class Size a where
sizeOf :: a -> Int
Пробуем обобщённый преобразователь:
*A2 Data.Data> :t fmap id . cast
fmap id . cast :: (Typeable a1, Typeable a) => a1 -> Maybe a
*A2 Data.Data> :t fmap show . cast
fmap show . cast :: (Typeable a) => a -> Maybe String
*A2 Data.Data> :t fmap (+1) . cast
fmap (+1) . cast :: (Num a, Typeable a1, Typeable a) =>
a1 -> Maybe a
*A2 Data.Data> :t fmap sizeOf . cast
<interactive>:1:14:
Ambiguous type variable `a' in the constraints:
`Typeable a' arising from a use of `cast' at <interactive>:1:14-17
`Size a' arising from a use of `sizeOf' at <interactive>:1:5-10
Probable fix: add a type signature that fixes these type variable(s)
Почему в последнем случае ошибка? Должно быть, как в случае (fmap show . cast).
Ан нет.