Haskell 默认约束类型将被忽略
我在定义默认约束时遇到了一个奇怪的问题。如果约束为unit,则不会选择默认实例。在所有其他情况下,它都按预期工作Haskell 默认约束类型将被忽略,haskell,default,type-constraints,Haskell,Default,Type Constraints,我在定义默认约束时遇到了一个奇怪的问题。如果约束为unit,则不会选择默认实例。在所有其他情况下,它都按预期工作 {-# LANGUAGE TypeFamilies, ConstraintKinds #-} import qualified GHC.Exts as E class Expression a where type Constr a v :: E.Constraint --type Constr a v = () -- with this line comp
{-# LANGUAGE TypeFamilies, ConstraintKinds #-}
import qualified GHC.Exts as E
class Expression a where
type Constr a v :: E.Constraint
--type Constr a v = () -- with this line compilation fails
--type Constr a v = v ~ v -- compiles
wrap :: Constr a v => a -> Maybe v
instance Expression () where
wrap () = Just undefined
main = print (wrap () :: Maybe Int)
有人能解释一下typechecker行为的原因吗?这不是一个真正的答案,但这不是关于
ConstraintKinds
class Expression a where
type Type a v
type Type a v = ()
wrap :: (Type a v) ~ () => a -> Maybe v
instance Expression () where
wrap () = Just undefined
main = print (wrap () :: Maybe Int)
不编译,但
class Expression a where
type Type a v
type Type a v = v
wrap :: (Type a v) ~ v => a -> Maybe v
instance Expression () where
wrap () = Just undefined
main = print (wrap () :: Maybe Int)
是否这是一个与7.4.1中的默认类型相关联的错误。几周前,我在#haskell上被告知这是一个已修复的已知错误,但我在GHC trac上找不到它的提及。猜测一下,因为
v
类型与关联类型映射解析的内容之间没有联系?可能相关: