Haskell. Strict application $!
haskell, lazy-evaluation, optimization
Solution
So you expect the list to be fully evaluated. ($!) is implemented in terms of `seq`, and `seq` "only" evaluates to head normal form according to the docs. It'll only make a difference if the value is `undefined`:
Prelude> take 0 undefined
[]
Prelude> take 0 $! undefined
*** Exception: Prelude.undefined
A function is strict in its argument if
f undefined = undefined
This does not imply that the argument is fully evaluated in an eager fashion. What you want is something like DeepSeq.
GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling DeepSeq ( deepSeq.lhs, interpreted )
Ok, modules loaded: DeepSeq.
*DeepSeq> take 1 $!! [1,2,undefined]
*** Exception: Prelude.undefined
*DeepSeq>
Your example with `$!!` from `DeepSeq` runs forever.
Problem
I execute the next code: ``` (take 10) $! [1,2..] ``` What is it ? I thought, ghc will yield a termination, beacause i say "evaluate [1,2..] force". But I got the result "[1,2,3,4,5,6,7,8,9,10]".