GHC 8.0.1では、タイプレベルのリストに対してタイプレベルLength
を実装しようとしています。無効なネスト型ファミリアプリケーション(これを許可するにはUndecidableInstancesを使用してください)
{-# LANGUAGE DataKinds, TypeOperators, TypeFamilies #-}
data Nat = Z | S Nat
type family Length (l :: [*]) :: Nat where
Length '[] = Z
Length (_ ': as) = S (Length as)
しかし、私はTypeLits
を使用している場合、それはコンパイルされません:それはコンパイル
import GHC.TypeLits
type family Length (l :: [*]) :: Nat where
Length '[] = 0
Length (_ ': as) = 1 + Length as
をコンパイラが次のエラー得られます。
• Illegal nested type family application ‘1 + Length as’
(Use UndecidableInstances to permit this)
• In the equations for closed type family ‘Length1’
In the type family declaration for ‘Length1’
「UndecidableInstances」をオンにしてください。 GHCの終了チェッカーは特に洗練されていません。別のタイプのファミリーのRHS上のタイプファミリーを使用することは、禁止されているものの1つです。 –