Skip to content

Type family & typeclass interaction suppresses errors

The following program despite having a hole and an undefined variable iDontExist *quietly* fails to compile on 8.4.3 and 8.4.4. It produces errors as expected on 8.6.1 and 8.6.2.

By quietly failing, I mean it fails on CLI but without producing any error messages and in GHCI. It just says "Failed, no modules loaded."

{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}

module Bug where

import Data.Kind (Type)

type Exp a = a -> Type
type family Eval (e :: Exp a) :: a

data OpKind = Conjunction

data Dual (k :: OpKind) :: Exp OpKind

data Map :: (a -> Exp b) -> [ a ] -> Exp [ b ]

type instance Eval (Map f (a ': as)) = Eval (f a) ': Eval (Map f as)

data Big :: [ OpKind ] -> Type where
  Big  :: [ Big ks ] -> Big ('Conjunction ': ks)

dualBig :: Big ks -> Big (Eval (Map Dual ks))
dualBig = _

instance Semigroup (Big a) where
  Big xs <> Big ys = Big (xs <> ys)

instance Monoid (Big ('Conjunction ': ks)) where
  mempty = iDontExist

flatten :: Monoid (Big ks) => Big (k ': k ': ks) -> Big ks
flatten = undefined

Sorry, the example is a bit big but almost any change causes the errors to appear again including the Monoid constraint on flatten.

Trac metadata
Trac field Value
Version 8.4.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information