Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Seq
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Controversy? === The presence of <code>seq</code> in Haskell does have some disadvantages: :{| |- style="vertical-align:top;" |1. |It is the only reason why Haskell programs are able to distinguish between the following two values: <haskell> undefined :: a -> b const undefined :: a -> b </haskell> This violates the principle of extensionality of functions, or eta-conversion from the lambda calculus, because <code>f</code> and <code>\x -> f x</code> are distinct functions, even though they return the same output for every input. |- style="vertical-align:top;" |2. |It can invalidate [[Correctness of short cut fusion|optimisation techniques]] which would normally be safe, causing the following two expressions to differ: <haskell> foldr β₯ 0 (build seq) = foldr β₯ 0 (seq (:) []) = foldr β₯ 0 [] = 0 seq β₯ 0 = β₯ </haskell> This weakens the ability to use parametricity, which implies <code>foldr k z (build g) == g k z</code> for suitable values of <code>g</code>, <code>k</code> and <code>z</code>. |- style="vertical-align:top;" |3. |It can invalidate laws which would otherwise hold, also causing expressions to have differing results: <haskell> seq (β₯ >>= return :: State s a) True = True seq (β₯ :: State s a) True = β₯ </haskell> This violates the first [[Monad laws|monad law]], that <code>m >>= return == m</code>. |} But <code>seq</code> (sequential or otherwise) isn't alone in causing such difficulties: :{| |- style="vertical-align:top;" |1. |When combined with call-by-need semantics, the use of weak-head normal form [https://www.pauldownen.com/publications/first-class-call-stacks.pdf is also detrimental to extensionality]. |- style="vertical-align:top;" |2. |When combined with GADTs, the associated map functions which uphold the functor laws [https://arxiv.org/pdf/2105.03389v3 is also problematic for parametricity]. |- style="vertical-align:top;" |3. |The ability to define the fixed-point combinator in Haskell using recursion: <haskell> yet :: (a -> a) -> a yet f = f (yet f) </haskell> means [https://dl.acm.org/doi/pdf/10.1145/99370.99404 parametricity is further restricted]. |- style="vertical-align:top;" |4. |Strictness must be considered when [https://ris.utwente.nl/ws/portalfiles/portal/284115323/thesis_M_Fokkinga.pdf deriving laws for various recursive algorithms] (see chapter 6). |- style="vertical-align:top;" |5. |Similar to <code>seq</code> and <code>β₯</code>, the use of division and zero present their own challenges! |} Therefore all such claims against <code>seq</code> (or calls for its outright removal) should be examined <i>in this context</i>.
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width