Type Level Ifについて
前記事 http://xenophobia.hatenablog.com/entry/2014/05/07/004251 書いてるときにふと、型レベルのIf使ったほうがいいのかなと一瞬思ったりしました。
singletonsパッケージのData.Singletons.Types(https://hackage.haskell.org/package/singletons-0.10.0/docs/Data-Singletons-Types.html)とかに型レベルのIfが置いてありますが、Type familyの「評価」ってそもそもLazyなんですかね。LazyだったらちゃんとIfとして機能しますが。というわけでやってみました。
結果、ループにハマりました。つまりこのコードにおいては引数部分が先に評価されている。
Line 10: 1 error(s), 0 warning(s) Context reduction stack overflow; size = 201 Use -fcontext-stack=N to increase stack size to N Loop Int ~ uf0 In the expression: undefined :: If True Int (Loop Int) In an equation for `a': a = undefined :: If True Int (Loop Int) In the expression: do { let a = undefined :: If True Int (Loop Int); print "Hello" }
ということは式とは違って評価はStrictっぽい?ちょっと意外。