> What this means for me is that:
>
> sum (x:xs) s = case (x+s) of
> s' -> sum xs s'
>
> does not force the evaluation of x+s. It still builds a thunk! Unless we
> do something like:
>
> sum (x:xs) s = case (x+s) of
> s'@(I# t#) -> sum xs s'
>
> Which then brings up the question of how does ghc perform strictness
> transformation? ... or does it? Does it do it like the above example?
Your analysis is completely right for Haskell. But internally, GHC
transforms the Haskell input into a simple form of functional program
(the Core program) before it applies transformations to the code. In
this internal code, the scrutinee of a case expression is always
evaluated, which in turn allows the GHC to perform the strictness
transformations.
Cheers,
Manuel