Skip to content

Commit a459f49

Browse files
committed
Split out the foldr example
「BangPattern をつけてはいけないところは, Strict 拡張でも lazy を明示的に指定しなくてはいけないので,ここら辺も NoStrict の時と注意点が同じと言う感じですね」の例としてfoldrの例を分ける
1 parent adac611 commit a459f49

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{-
2+
stack exec ghc -- -O0 -rtsopts -with-rtsopts=-K1k ./stackoverflow.hs
3+
stack exec ghc -- -O0 -rtsopts -with-rtsopts=-K1k -XStrict ./stackoverflow.hs
4+
stack exec ghc -- -O1 -rtsopts -with-rtsopts=-K1k ./stackoverflow.hs
5+
stack exec ghc -- -O1 -rtsopts -with-rtsopts=-K1k -XStrict ./stackoverflow.hs
6+
-}
7+
8+
import Control.Exception
9+
import Data.List
10+
11+
main :: IO ()
12+
main = do
13+
let size = 5000
14+
putStrLn "BEGIN"
15+
evaluate $ foldl (\z x -> x : z) [] [1 .. size]
16+
putStrLn "DONE"

examples/strict-gotchas/stackoverflow.hs renamed to examples/strict-gotchas/stackoverflow-foldr.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,5 @@ main = do
1616
evaluate $ foldr (:) [] [1 .. size]
1717
putStrLn "DONE: foldr 1"
1818

19-
evaluate $ foldl (\z x -> x : z) [] [1 .. size]
20-
putStrLn "DONE: foldl"
21-
2219
evaluate $ foldr (\x z -> x : z) [] [1 .. size]
2320
putStrLn "DONE: foldr 2"

0 commit comments

Comments
 (0)