Questions tagged [strictness]

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

68 questions
5
votes
1 answer

Why is HashMap not in normal form upon series of inserts?

I've been trying to ensure the strictness of an in-memory model of a Haskell program using ghc-heap-view package and the utils it provides when I noticed that my HashMaps don't seem to be in NF upon a series on inserts. I tried printing Heap tree…
MantasG
  • 117
  • 1
  • 5
5
votes
2 answers

Existential data types with a single strict field

So I have an existential data type with a single strict field: data Uncurry (a :: i -> j -> *) (z :: (i,j)) = forall x y. z ~ '(x,y) => Uncurry !(a x y) Experimentation using unsafeSizeof (stolen from this answer) leads me to believe that it can…
rampion
  • 87,131
  • 49
  • 199
  • 315
5
votes
3 answers

Logical AND strictness with IO monad

I am trying to write a simple program in Haskell. It should basically run two shell commands in parallel. Here is the code: import System.Cmd import System.Exit import Control.Monad exitCodeToBool ExitSuccess = True exitCodeToBool (ExitFailure _) =…
user1179926
  • 137
  • 5
5
votes
3 answers

Type enforced "strict/imperitive" subset/version of Haskell

I quite like Haskell, however one of the main things that concerns me about Haskell the difficulty in reasoning about space usage. Basically the possibility of thunks and recursion seem to make some tricky situations where it seems one has to be…
Clinton
  • 22,361
  • 15
  • 67
  • 163
5
votes
3 answers

Haskell foldl' poor performance with (++)

I have this code: import Data.List newList_bad lst = foldl' (\acc x -> acc ++ [x*2]) [] lst newList_good lst = foldl' (\acc x -> x*2 : acc) [] lst These functions return lists with each element multiplied by 2: *Main> newList_bad…
4
votes
1 answer

How does evaluation in Haskell work, for expressions with constraints

Suppose I write in GHCi: GHCi> let x = 1 + 2 :: Integer GHCi> seq x () GHCi> :sprint x GHCi prints x = 3 as naturally expected. However, GHCi> let x = 1 + 2 GHCi> seq x () GHCi> :sprint x yields x = _ The sole difference between the two…
Matei
  • 152
  • 1
  • 5
4
votes
2 answers

Lazy state transformer consumes lazy list eagerly in 2D recursion

I'm using a state transformer to randomly sample a dataset at every point of a 2D recursive walk, which outputs a list of 2D grids of samples that together succeed a condition. I'd like to pull from the results lazily, but my approach instead…
concat
  • 3,107
  • 16
  • 30
4
votes
2 answers

How to make a table (Data.Map) strict in haskell?

For learning Haskell (nice language) I'm triying problems from Spoj. I have a table with 19000 elements all known at compile-time. How can I make the table strict with 'seq'? Here a (strong) simplified example from my code. import qualified Data.Map…
Jogusa
  • 5,530
  • 5
  • 24
  • 23
4
votes
2 answers

Is it possible to implement this function in Haskell?

At the page https://en.wikibooks.org/wiki/Haskell/Denotational_semantics#Pattern_Matching there is the following exercise: Consider a function or of two boolean arguments with the following properties: or ⊥ ⊥ = ⊥ or True ⊥ = True or ⊥ True =…
Federico
  • 582
  • 3
  • 12
4
votes
1 answer

Strict evaluation techniques for concurrent channels in Haskell

I'm toying with Haskell threads, and I'm running into the problem of communicating lazily-evaluated values across a channel. For example, with N worker threads and 1 output thread, the workers communicate unevaluated work and the output thread ends…
chrisleague
  • 558
  • 2
  • 15
3
votes
0 answers

Should NFData have a dual?

Haskell has a type called NFData with the following shape: class NFData a where rnf :: a -> () Types that are more "data-ish" than "function-ish" can be equipped with instances of NFData. Each such instance thoroughly case analyzes a given…
Asad Saeeduddin
  • 46,193
  • 6
  • 90
  • 139
3
votes
1 answer

Strict list evaluation in GHCi

Consider the program: l = [0..10] l' = map (+1) [0..10] Running it with GHCi, and typing :sprint l and :sprint l' will reveal both lists to be unevaluated. However, after running length l and length l' and then again using sprint: l =…
Matei
  • 152
  • 1
  • 5
3
votes
1 answer

GHC error for missing strict fields

I'm reading this article. It reads: When constructing a value with record syntax, GHC will give you an error if you forget a strict field. It will only give you a warning for non-strict fields. Can anyone give me a concrete example of this?
Marronnier
  • 389
  • 2
  • 10
3
votes
2 answers

Can sequence over infinite maybes ever terminate?

In other words, can the following be optimized to Just [1..]? > sequence (map Just [1..]) *** Exception: stack overflow There is also a more specific example in data61/fp-course where early termination is expected iff an Empty value is…
sevo
  • 4,559
  • 1
  • 15
  • 31
3
votes
2 answers

Operating infinite lists with strict monads

I have a function f :: [a] -> b that operates on infinite lists (e.g. take 5, takeWhile (< 100) . scanl (+) 0 and so on). I want to feed this function with values generated by strict monadic actions (e.g. randomIO). From this question, I've learned…
Douglas Vieira
  • 183
  • 1
  • 7