9
定義默認約束時,我遇到了一個奇怪的問題。如果約束是單位,則不選擇默認實例。在所有其他情況下,它按預期工作。忽略默認約束類型
{-# 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行爲的原因嗎?
有人猜測,因爲'v'類型與關聯類型映射解析爲什麼沒有關係? – ivanm
可能相關:[ConstraintKinds和默認關聯空約束](http://comments.gmane.org/gmane.comp.lang.haskell.glasgow.user/21058) – hammar