こわいはなし
{-# LANGUAGE TypeFamilies , ScopedTypeVariables #-} type family TF a f :: TF a -> Int f (v :: TF a) = 0
ghciに投げ込むと
/Users/ranha/Haskell/proghost% ghci kowai.hs GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package ffi-1.0 ... linking ... done. [1 of 1] Compiling Main ( kowai.hs, interpreted ) kowai.hs:6:3: Pattern signature must exactly match: TF a In the pattern: v :: TF a In the definition of `f': f (v :: TF a) = 0 Failed, modules loaded: none.
あと、
type instance TF a = Int
を追加してあげると
/Users/ranha/Haskell/proghost% ghci kowai.hs GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package ffi-1.0 ... linking ... done. [1 of 1] Compiling Main ( kowai.hs, interpreted ) ghc: panic! (the 'impossible' happened) (GHC version 6.12.3 for i386-apple-darwin): readFilledBox a{tv adF} [box] Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
と言われる。
問題設定
1.最初のコードはちょっとしたものを付け足すだけで(他の部分は変えずに!!)、(多分)割と意図した通りに動くようになります。何を書けば良いでしょう。
2.何故それをやると上手くいくのか。何故それをやらないときは上手くいかないのか。
答えが知りたい人は、ghciにddump-tc-traceオプションを付けて実行してみましょう。簡単に分かりますよ。