[Haskell-cafe] Re: evaluate vs seq
Michael Shulman
viritrilbia at gmail.com
Wed Sep 13 16:24:42 EDT 2006
On 9/13/06, apfelmus at quantentunnel.de <apfelmus at quantentunnel.de> wrote:
> So `seq` forces its first argument. When we define
> f x = x `seq` (Return x)
> we thereby get
> f _|_ == _|_
> f [] == Return []
> f (x:xs) == Return (x:xs)
> To compare, the semantics of (evaluate) is
> evaluate _|_ == ThrowException =/= _|_
> evaluate [] == Return []
> evaluate (x:xs) == Return (x:xs)
> That should answer your question.
I must not be phrasing my question very well; I feel like we're
talking past each other. It seems to me that when writing actual
programs (rather than reasoning about denotational semantics) the
reason one would use `seq' or `evaluate' is to force something to be
evaluated "now" rather than "later", i.e. to get around Haskell's
default lazy execution.
Your semantics say that (x `seq` return x) and (evaluate x) have the
same result when x is anything other than _|_. All well and good, but
(return x) *also* has those same results when x is not _|_. Why would
one use the former two rather than (return x), if x is known not to be
_|_? Because they evaluate x at different "times", right? Even though
the eventual return value is the same, and thus the *semantics* are the
same. So laying aside the formal semantics, what is the difference in
terms of actual, real, Haskell programs?
Mike
More information about the Haskell-Cafe
mailing list