In the semantics of Haskell, strictness relates to whether evaluating an expression forces evaluation of a sub-expression.
Questions tagged [strictness]
68 questions
1
vote
2 answers
Can pseq be defined in terms of seq?
As far as I know, seq a b evaluates (forces) a and b before returning b. It does not guarantee that a is evaluated first.
pseq a b evaluates a first, then evaluates/returns b.
Now consider the following:
xseq a b = (seq a id) b
Function application…

melpomene
- 84,125
- 8
- 85
- 148
1
vote
1 answer
Mapping a strict vs. a lazy function
(head . map f) xs = (f . head) xs
It works for every xs list when f is strict.
Can anyone give me example, why with non-strict f it doesnt work?

beja
- 29
- 2
1
vote
0 answers
Avoiding CAF in Haskell
To avoid CAF (resource sharing), I tried converting to function
with dummy argument, but no success (noCafB).
I've read How to make a CAF not a CAF in Haskell? so tried noCafC and noCafD. When compiled with
-O0, then functions with dummy argument…

Chul-Woong Yang
- 1,223
- 10
- 17
1
vote
2 answers
strict evaluation of integer accumulator
Here is a classic first attempt at a custom length function:
length1 [] = 0
length1 (x:xs) = 1 + length1 xs
And here is a tail-recursive version:
length2 = length2' 0 where
length2' n [] = n
length2' n (x:xs) = length2' (n+1)…

fredoverflow
- 256,549
- 94
- 388
- 662
0
votes
0 answers
Scala call-by-name arguments: Equivalent to functions with no arguments? Or not..?
1 def nonStrict[A](a: () => A) = a
2 def nonStrict[A](a: => A) = a
I'm reading the red scala book which presents => A as 'nicer syntax' for () => A
but 1 and 2 are apparently not equivalent
scala> def nonStrict[A](a: => A) = a
def nonStrict[A](a: =>…

A.Lee
- 1
- 2
0
votes
2 answers
How can I optimise my Haskell so I don't run out of memory
For an online algorithms course I am attempting to write a program which calculates the travelling salesman distance of cities using an approxomation algorithm:
Start the tour at the first city.
Repeatedly visit the closest city that the tour…

mattematt
- 445
- 3
- 10
0
votes
2 answers
About strictness in haskell
I've created the following Haskell prime function (within ghci):
let pi :: Int -> Int -> Int;
pi 1 _ = 2;
pi x y = if all (/=0) (map (rem y) [pi z 2| z <- [1..(x-1)]]) then y else pi x (y+1);
Please don't mind the second/memoized argument (it…

dumb0
- 337
- 1
- 8
0
votes
1 answer
Missing something with strictness
I have this code:
divisors n = 1:[y|y<-[2..(n `div` 2)], n `mod` y == 0]
writeList l = do print "Start"
print l
Then, i want to call the function with strict argument; i tried:
writeList $! (divisors 12345678)
and
(divisors…

Aslan986
- 9,984
- 11
- 44
- 75