[Haskell-cafe] how to optmize this code?

Ryan Ingram ryani.spam at gmail.com
Fri Apr 1 00:28:39 CEST 2011


On Thu, Mar 31, 2011 at 7:29 AM, Daniel Fischer <
daniel.is.fischer at googlemail.com> wrote:

> Err, terminology problem here.
> Strictly speaking, a function is strict iff
>
> f _|_ = _|_
>
> while we are talking here about evaluation strategies, so we should better
> have spoken of eager vs. deferred evaluation.
> A non-strict function has different semantics from a strict one by
> definition.
>
> If you have a strict function, you may evaluate its argument eagerly
> without changing the result¹, while eager evaluation of a non-strict
> function's argument may produce _|_ where deferred evaluation wouldn't.
>

This is almost but not entirely true.  Consider

f x = error "f is not implemented"

Clearly, f _|_ = _|_, so f is strict.

f (error "bang!")

might, depending on how strictness analysis proceeds, generate an "f is not
implemented" error or a "bang!" error.  But that's only observable at the IO
level, and the optimization is considered important enough, that potentially
generating a different exception is allowed.

I think this paper covers some of the details:
http://research.microsoft.com/en-us/um/people/simonpj/papers/imprecise-exn.htm

  -- ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110331/ef592cca/attachment-0001.htm>


More information about the Haskell-Cafe mailing list