[Haskell-cafe] Expressing seq
Bertram Felgenhauer
bertram.felgenhauer at googlemail.com
Wed Sep 27 18:10:21 EDT 2006
Chad Scherrer wrote:
> Prelude> let sq x y = if x == x then y else y
> Prelude> 1 `sq` 2
> 2
> Prelude> (length [1..]) `sq` 2
> Interrupted.
> There must be a subtlety I'm missing, right?
Two, at least:
First, your sq has a different type, as it requires an Eq instance:
Prelude> :t sq
sq :: (Eq a) => a -> t -> t
Prelude> :t seq
seq :: a -> b -> b
Secondly, your sq is more akin to a deepSeq in that it forces all of
its value instead of just evaluating to weak head normal form.
Prelude> [undefined] `seq` 1
1
Prelude> [undefined] `sq` 1
*** Exception: Prelude.undefined
You could implement seq explicitely for many types, for example,
seqList [] x = x
seqList (_:_) x = x
but not for function types.
HTH,
Bertram
More information about the Haskell-Cafe
mailing list