I am new to haskell, and have just come to the lazy world proramming. I read that the seq
function is very special because it forces to use a strict evaluation in order to be more efficient in some cases. But I just can't find what seq
stand for literally. Maybe Strict Evaluation Q*???
seq
evaluates its first argument before returning the second one. It is usually introduced to improve performance by avoiding unneeded laziness. It forces evaluation of the function.
seq :: a -> b -> b
seq _ y = y
from prelude.hs
This function definition is wrapped in
#ifdef __HADDOCK__
so it will only be compiled by haddock (the documentation tool), not by the actual compiler! The 'real' seq is defined in GHC.Prim asseq :: a -> b -> b; seq = let x = x in x.
This is only a dummy definition. Basically seq is specially syntax handled particularly by the compiler. You wrote 'seq evaluates its first argument' - but first definition obviously does not do this.
via user2407038
More to read:
seq
is defined! Do the following: myseq _ y = y
. seq undefined ()
== undefined
but myseq undefined ()
== ()
. The definition you gave for seq
is precisely the opposite of what it actually does. seq
is actually not defined 'in haskell'; it is a primitive. –
Patino flip const
. seq
cannot be defined in normal Haskell. –
Jueta #ifdef __HADDOCK__
so it will only be compiled by haddock (the documentation tool), not by the actual compiler! The 'real' seq
is defined in GHC.Prim
as seq :: a -> b -> b; seq = let x = x in x
. This is only a dummy definition. Basically seq
is specially syntax handled particularly by the compiler. You wrote 'seq evaluates its first argument' - but your definition obviously does not do this. –
Patino It is supposed to remind you of "sequentially" or "sequence" because it allows the programmer to specify the sequence of evaluation of its arguments.
seq
doesn't actually force the arguments to be evaluated in sequence. You need pseq
for that. –
Focalize seq
evaluates its first argument before returning the second one. It is usually introduced to improve performance by avoiding unneeded laziness. It forces evaluation of the function.
seq :: a -> b -> b
seq _ y = y
from prelude.hs
This function definition is wrapped in
#ifdef __HADDOCK__
so it will only be compiled by haddock (the documentation tool), not by the actual compiler! The 'real' seq is defined in GHC.Prim asseq :: a -> b -> b; seq = let x = x in x.
This is only a dummy definition. Basically seq is specially syntax handled particularly by the compiler. You wrote 'seq evaluates its first argument' - but first definition obviously does not do this.
via user2407038
More to read:
seq
is defined! Do the following: myseq _ y = y
. seq undefined ()
== undefined
but myseq undefined ()
== ()
. The definition you gave for seq
is precisely the opposite of what it actually does. seq
is actually not defined 'in haskell'; it is a primitive. –
Patino flip const
. seq
cannot be defined in normal Haskell. –
Jueta #ifdef __HADDOCK__
so it will only be compiled by haddock (the documentation tool), not by the actual compiler! The 'real' seq
is defined in GHC.Prim
as seq :: a -> b -> b; seq = let x = x in x
. This is only a dummy definition. Basically seq
is specially syntax handled particularly by the compiler. You wrote 'seq evaluates its first argument' - but your definition obviously does not do this. –
Patino © 2022 - 2024 — McMap. All rights reserved.