9

当使用类型族的数据类型时,我发现了一个有趣的情况。

编译器的错误信息是No instance for (C (ID ())) arising from a use of W. 这表明类型族应用程序没有得到充分评估,即使它已经饱和。:kind! ID ()计算结果为(),因此应根据C ()实例使用。

{-# 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)

我可以以某种方式强制评估ID ()吗?它是编译器错误吗?

我正在使用 GHC 7.8.3

4

1 回答 1

2

问题是那种ConstID

type family ConstID t a where
  ConstID t a = ID a
于 2014-09-17T08:53:56.067 回答