有没有可能知道(在编译时)在实例重叠的情况下编译器选择了哪个实例?
人为的例子,
{-# LANGUAGE IncoherentInstances #-}
class Transformable a b where
transform :: a -> b
instance Transformable a Int where
transform _ = 17
instance a ~ b => Transformable a b where
transform x = xtranform (1:: Int) :: Int的结果是什么?(1或17)在实例化Transformable Int Int时,有没有办法知道编译器选择实例1还是实例2?当没有重叠,但实例化的链很复杂时,它有时也很有用。
发布于 2016-05-31 01:56:39
您可以随时使用Debug.Trace
import Debug.Trace
...
instance Transformable a Int where
transform _ = trace "using Int definition" 17
instance a ~ b => Transformable a b where
transform x = trace "using a ~ b definition" xhttps://stackoverflow.com/questions/37530987
复制相似问题