In the definition of the haskell prelude we see that ...
is reserved for expressions that cannot be implemented in Haskell. Now the IO
monad for example can't be implemented in haskell.
What surprised me is that seq
is defined as follows in the prelude
seq :: a -> b -> b
seq = ... -- Primitive
Why not the following? what am i missing?
seq _ b = b
As you can see in the Haskell Wiki entry on seq
, the seq
function must fulfil the following two equations:
⊥ `seq` b = ⊥
a `seq` b = b
(where ⊥
is the undefined value, which is what non-terminating function applications or things like hd []
and undefined
evaluate to logically)
Your definition clearly does not fulfil the first equation.
The typical use case for seq
is to force evaluation of the first parameter (to weak head normal form) before evaluating the second one. (although, strictly speaking, seq
does not guarantee that; see again the wiki article)
Such a function is, to my knowledge, not definable in pure Haskell without any compiler extensions like -XBangPatterns
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.