EDIT: . . , , ghc -O0 -ddump-simpl main.hs fib Core:
Main.fib :: forall a_agB. GHC.Num.Num a_agB => () -> [a_agB]
O2 optimizations ghc -O2 -ddump-simpl main.hs
Main.$wfib :: forall a_agG. GHC.Num.Num a_agG => [a_agG]
Fibonacci ( ())
Main.fib =
\ (@ a_agG) (w_stM :: GHC.Num.Num a_agG) (w1_stN :: ()) ->
case w1_stN of _ { () -> Main.$wfib @ a_agG w_stM }
, Main.fib memoized, Main.$wfib .
:
, ,
val = 1+2+3
, . , ,
val () = 1+2+3
, () val, . , val , , . , :
fib = 0 : 1 : zipWith (+) fib (tail fib)
fib !! 100000, 100 000 . fib , , . ,
fib () = let x = 0 : 1 : zipWith (+) x (tail x) in x
fib () , , .
Edit: as Philippe JF said in the comments, the contents of the let statement could be stripped by an unfriendly compiler, resulting in unwanted sharing
Boris source
share