【发布时间】:2019-10-19 09:15:28
【问题描述】:
考虑这段代码:
{-# language FlexibleInstances, UndecidableInstances #-}
module Y where
class C m where
x :: m
instance {-# overlappable #-} Monoid m => C m where
x = mempty
instance C Int where
x = 53
x的类型是什么?
λ :type x
x :: C m => m
到目前为止——非常好。现在删除 Int 实例。 x的类型是什么?
λ :type x
x :: Monoid m => m
惊喜!
为什么会这样?
【问题讨论】:
标签: haskell type-inference typeclass