[Haskell-cafe] Problems with strictness analysis?

Luke Palmer lrpalmer at gmail.com
Mon Nov 3 16:49:54 EST 2008


On Mon, Nov 3, 2008 at 2:35 PM, Don Stewart <dons at galois.com> wrote:
> Consider this program,
>
>            isum  0  s = s
>            isum  n  s = isum (n-1) (s+n)
>
>            main = case isum 10000000 0 {- rsum 10000000 -} of
>                     0 -> print 0
>                     x -> print x
>
> Now, isum is *not* strict in 's', [...]
>
> Of course, we make this strict in a number of ways:
>
> * Turning on optimisations:

I am confused about your usage of "strict".  Optimizations are not
supposed to change semantics, so I don't know how it is possible to
make a function strict by turning on optimizations.  This function was
always strict in s, given a strict numeral type.  By induction on n:

  isum 0 _|_ = _|_
  isum (n+1) _|_ = isum n (s+_|_) = isum n _|_ = _|_

For negative n, it either wraps around to positive in which case the
above analysis applies, or it does not halt, which is strict (in the
same way "const _|_" is strict).

Luke


More information about the Haskell-Cafe mailing list