# Understanding strictness of ghc output

Adrian Hey ahey at iee.org
Tue Jun 22 08:30:16 EDT 2004

```Hello,

I'm trying to figure out how you tell if ghc has correctly infered
strictness or whether or not a little more prompting from me
is needed.

I tried compiling with -ddump-simpl, and I guess from looking
at this the DmdType bit is what I want (maybe). So if I have
"DmdType LS" for a function of arity 2, does this mean the
function is lazy in the first argument and strict in the second?

I would be pretty confident that this was the correct interpretation,
but this is the Haskell code (from AVL library)..

height :: AVL e -> Int
height = addHeight 0 where
addHeight h  E        = h
addHeight h (N l _ _) = addHeight h+2 l
addHeight h (Z l _ _) = addHeight h+1 l
addHeight h (P _ _ r) = addHeight h+2 r

It seems pretty obvious to me that addHeight is strict in its
first argument if + is strict for Ints (as I guess it is). But this
gives "DmdType LS".

Even if I rewrite it..

height :: AVL e -> Int
height = addHeight 0 where
addHeight h  E        = h
addHeight h (N l _ _) = let h' = h+2 in h' `seq` addHeight h' l
addHeight h (Z l _ _) = let h' = h+1 in h' `seq` addHeight h' l
addHeight h (P _ _ r) = let h' = h+2 in h' `seq` addHeight h' r

.. it still gives "DmdType LS".

So does this..

height :: AVL e -> Int
height = addHeight 0 where
addHeight h  E        = h
addHeight h (N l _ _) = h `seq` addHeight (h+2) l
addHeight h (Z l _ _) = h `seq` addHeight (h+1) l
addHeight h (P _ _ r) = h `seq` addHeight (h+2) r

So am I interpreting core correctly?

Thanks
--