Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell type family applications are not evaluated

I found an interesting situation, when using data kinds with type families.

The compiler's error message is No instance for (C (ID ())) arising from a use of W. It suggests that a type family application is not fully evaluated, even when it is saturated. :kind! ID () evaluates to (), so according to the C () instance should be used.

{-# LANGUAGE GADTs, TypeFamilies, UndecidableInstances, FlexibleContexts #-}

type family ID t where
  ID t = t

class C t where
instance C () where

data W where
  W :: C (AppID t) => P t -> W

type family AppID t where
  AppID t = (ConstID t) ()

type family ConstID t where
  ConstID t = ID

data P t where
  P :: P t

data A

w :: W
w = W (P :: P A)

Could I somehow force the evaluation of ID ()? Is it a compiler bug?

I'm using GHC 7.8.3

like image 398
Boldizsár Németh Avatar asked Sep 16 '14 16:09

Boldizsár Németh


1 Answers

The problem is the kind of ConstID.

type family ConstID t a where
  ConstID t a = ID a
like image 102
Kelemen Zoltán Avatar answered Oct 04 '22 03:10

Kelemen Zoltán