1

GHC.TypeLits をいじって このコードを作りました

data A (a :: Symbol) = A
type B a (b :: Symbol) (c :: Symbol) = A a

class AC a where
  af :: (String, a)

-- instance SingI a => AC (A a) where
--   af = (fromSing (sing :: Sing a), A)

instance (SingI a, SingI b, SingI c) => AC (B a b c) where
  af = (fromSing (sing :: Sing c), A)

このエラーでどこかで af を呼び出そうとすると、コンパイルに失敗します:

No instance for (SingI Symbol c) arising from a use of `af'
Possible fix: add an instance declaration for (SingI Symbol c)
In the second argument of `($)', namely
  `(af :: (String, B "a" "b" "c"))'
In the second argument of `($)', namely
  `fst $ (af :: (String, B "a" "b" "c"))'
In a stmt of a 'do' block:
  print $ fst $ (af :: (String, B "a" "b" "c")) 

それが型の同義語を持つものであることは明らかであるため、それでも問題なく動作しinstance SingI a => AC (A a)ますが、これについての説明は見つかりません。なぜこのように機能するのかを聞いてうれしいです.タグのキングオブタグをタイプシノニムに追加する機会はありますか?

コンパイルに使用される拡張子:

  DataKinds,
  KindSignatures,
  TypeSynonymInstances,
  ScopedTypeVariables,
  -- MultiParamTypeClasses,
  UndecidableInstances
4

1 に答える 1