strictness

Haskell foldl' poor performance with (++)

假装没事ソ 提交于 2019-11-26 04:56:08
问题 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 [1..10] [2,4,6,8,10,12,14,16,18,20] *Main> newList_good [1..10] [20,18,16,14,12,10,8,6,4,2] In ghci: *Main> sum $ newList_bad [1..15000] 225015000 (5.24 secs, 4767099960 bytes) *Main> sum $ newList_good [1..15000] 225015000 (0.03 secs, 3190716 bytes) Why newList

What is Weak Head Normal Form?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 01:34:38
问题 What does Weak Head Normal Form (WHNF) mean? What does Head Normal form (HNF) and Normal Form (NF) mean? Real World Haskell states: The familiar seq function evaluates an expression to what we call head normal form (abbreviated HNF). It stops once it reaches the outermost constructor (the “head”). This is distinct from normal form (NF), in which an expression is completely evaluated. You will also hear Haskell programmers refer to weak head normal form (WHNF). For normal data, weak head