I encountered a strange problem when defining a default constraint. If a constraint is unit, the default instance is not chosen. In all other cases, it works as expected.
{-# 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)
Can someone clarify the reasons of the typechecker behavior?
This is a bug with associated type defaults in 7.4.1. A few weeks ago, I was told on #haskell that it is a known bug that has been fixed, but I can't find mention of it on the GHC trac.