Questions tagged [strictness]

In the semantics of Haskell, strictness relates to whether evaluating an expression forces evaluation of a sub-expression.

68 questions
11
votes
2 answers

What does “⊥” mean in “The Strictness Monad” from P. Wadler's paper?

Can someone help me understand the following definition from Wadler's paper titled "Comprehending Monads"? (Excerpt is from section 3.2/page 9, i.e., the "Strictness Monad" subsection.) Sometimes it is necessary to control order of evaluation in…
iceman
  • 2,020
  • 2
  • 17
  • 24
11
votes
2 answers

Evaluation and space leaks in Haskell

I'm learning Haskell and currently trying to wrap my head around monads. While playing with some random number generation I got tripped on lazy evaluation once again. In an effort to simplify something close to the: roll :: State StdGen Int roll =…
nope
  • 387
  • 1
  • 3
  • 8
11
votes
1 answer

Debugging unwanted strictness?

I have a problem that I don't know how to reason about. I was just about to ask if somebody could help me with the specific problem, but it dawned on me that I could ask a more general question and hopefully get a better general understanding as a…
mergeconflict
  • 8,156
  • 34
  • 63
10
votes
1 answer

Strict fmap using only Functor, not Monad

One irritation with lazy IO caught to my attention recently import System.IO import Control.Applicative main = withFile "test.txt" ReadMode getLines >>= mapM_ putStrLn where getLines h = lines <$> hGetContents h Due to lazy IO, the above program…
Dan Burton
  • 53,238
  • 27
  • 117
  • 198
9
votes
1 answer

Infinite recursion when enumerating all values of a Generic instance

For another answer of mine, I wrote the following code, providing diagonally traversed Universe instances for enumerable Generics (it's slightly updated from the version there, but uses the same logic): {-# LANGUAGE DeriveGeneric, TypeOperators,…
phipsgabler
  • 20,535
  • 4
  • 40
  • 60
8
votes
1 answer

Does Haskell have a strict Set container?

If we look at the containers package. They have Data.Map.Strict, but there is no equivalent Data.Set.Strict. Would it make sense for it to exist?
Tarrasch
  • 10,199
  • 6
  • 41
  • 57
8
votes
1 answer

Example of performance degradation due to the use of strict data constructors

I'm reading about strict data constructors. The linked Wiki article states that, "strictness annotations can make performance worse [because] a strictness annotation forces the compiler to ensure that the field is fully evaluated before building…
Damian Nadales
  • 4,907
  • 1
  • 21
  • 34
8
votes
1 answer

How is Haskell's seq used?

So, Haskell seq function forces the evaluation of it's first argument and returns the second. Consequently it is an infix operator. If you want to force the evaluation of an expression, intuitively such a feature would be a unary operator. So,…
George
  • 2,451
  • 27
  • 37
7
votes
3 answers

What's the meaning of strict version in haskell?

Follow , it is said foldl' are strict version of foldl. But it's hard for me to understand , what does strict mean?? foldl f z0 xs0 = lgo z0 xs0 where lgo z [] = z lgo z (x:xs) = lgo (f z…
jackalope
  • 1,554
  • 3
  • 17
  • 37
6
votes
1 answer

Haskell computation performance

I have several different implementations of the same function. The difference lies in the use of bang patterns. The question is, why does perimeterNaiveFast work the same as perimeterStrictFast? Benchmark results: Function realisations: > data…
6
votes
1 answer

Automatically inserting laziness in Haskell

Haskell pattern matching is often head strict, for example,f (x:xs) = ... requires input list to be evaluated to (thunk : thunk). But sometimes such evaluation is not needed and function can afford to be non-strict on some arguments, for example f…
Jun Xu
  • 161
  • 1
6
votes
4 answers

Does the existence rseq/seq break referential transparency? Are there some alternative approaches that don't?

I always thought that replacing an expression x :: () with () :: () would be one of the most basic optimizations during compiling Haskell programs. Since () has a single inhabitant, no matter what x is, it's result is (). This optimization seemed to…
Petr
  • 62,528
  • 13
  • 153
  • 317
5
votes
2 answers

Why map does not force strictness whereas zipWith does?

There are two strict versions of zipWith function: 1) Really strict, elements of lists l1 and l2 get evaluated so their thunks do not eat all stack space (Don Stewart code) zipWith' f l1 l2 = [ f e1 e2 | (e1, e2) <- zipWith k l1 l2 ] …
David Unric
  • 7,421
  • 1
  • 37
  • 65
5
votes
1 answer

Why is foldr' not as strict as foldl'?

Consider these various attempts at something that works like last: Prelude> import Data.Foldable Prelude Data.Foldable> foldr const undefined (reverse [1,2,3]) 3 Prelude Data.Foldable> foldr' const undefined (reverse [1,2,3]) 3 Prelude…
5
votes
1 answer

An unexpected property of commutative functions?

I have derived a statement (theorem?) that puzzles me. I wonder if my logic is sound. Any commutative non-strict function f :: a -> a -> b is a constant. Commutativity is understood including the bottoms, i.e. f x y and f y x either both…
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243