Archive for February, 2007

GHC sometimes loops

Friday, February 9th, 2007 by Wouter

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