Teach SpecConstr how to handle mutually-recursive functions
authorsimonpj@microsoft.com <unknown>
Wed, 29 Nov 2006 21:39:31 +0000 (21:39 +0000)
committersimonpj@microsoft.com <unknown>
Wed, 29 Nov 2006 21:39:31 +0000 (21:39 +0000)
commit9fad5a80e55f3a36b7da09031e77324f67ab08d1
tree1020e8ff597e33cd9cd6d8d58e17aa4319e1a61e
parent1dca158769225e58ec90d95526f968515e325378
Teach SpecConstr how to handle mutually-recursive functions

Roman found cases where it was important to do SpecConstr for
mutually-recursive definitions.  Here is one:
foo :: Maybe Int -> Int
foo Nothing  = 0
foo (Just 0) = foo Nothing
foo (Just n) = foo (Just (n-1))
By the time SpecConstr gets to it, it looks like this:
lvl = foo Nothing
foo Nothing  = 0
foo (Just 0) = lvl
foo (Just n) = foo (Just (n-1))

Happily, it turns out to be rather straightforward to generalise the
transformation to mutually-recursive functions.  Look, ma, only 4
extra lines of ocde!
compiler/specialise/SpecConstr.lhs