Nottingham FP Lab Blog

GHC sometimes loops

by Wouter on February 9, 2007.
Tagged as: Lunches.

I gave a quick demo on how to make ghc loop. The trick is to encode recursion using a data type, and then write a diverging term. The compiler’s aggresive inliner then gets carried away, resulting in divergance. Here’s the code:

 >data Evil = Evil (Evil -> Evil) >apply :: Evil -> Evil -> Evil >apply (Evil f) x = f x >delta :: Evil >delta = Evil (\x -> x `apply` x) >omega :: Evil >omega = delta `apply` delta

>data Evil = Evil (Evil -> Evil) >apply :: Evil -> Evil -> Evil >apply (Evil f) x = f x >delta :: Evil >delta = Evil (\x -> x `apply` x) >omega :: Evil >omega = delta `apply` delta


comments powered by Disqus