strict bits of datatypes

John Meacham john at repetae.net
Wed Mar 21 16:55:28 EDT 2007


On Mon, Mar 19, 2007 at 03:22:29PM +0000, Simon Peyton-Jones wrote:
> | This reminds me of something I discovered about using strict fields in
> | AVL trees (with ghc). Using strict fields results in slower code than
> | doing the `seq` desugaring by hand.
> 
> That is bad.  Can you send a test case that demonstrates this behaviour?
> 
> | If I have..
> |
> | data AVL e = E
> |             | N !(AVL e) e !(AVL e)
> | .. etc
> |
> | then presumably this..
> |
> | case avl of N l e r -> N (f l) e r
> |
> | desugars to something like ..
> |
> | case avl of N l e r -> let l' = f l
> |                         in l' `seq` r `seq` N l' e r
> |
> | but IMO it should desugar to..
> |
> | case avl of N l e r -> let l' = f l
> |                         in l' `seq` N l' e r
> 
> I agree.  If it doesn't please let me know!
> 

Although I have not looked into this much, My guess is it is an issue in
the simplifier, normally when something is examined with a case
statement, the simplification context sets its status to 'NoneOf []',
which means we know it is in WHNF, but we don't have any more info about
it. I would think that the solution would be to add the same annotation
in the simplifier to variables bound by pattern matching on strict data
types?

Just a theory. I am not sure how to debug this in ghc without digging
into it's code.

        John


-- 
John Meacham - ⑆repetae.net⑆john⑈


More information about the Haskell-prime mailing list