Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Evaluation, bang patterns, and deepseq

View ensure.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
{-# LANGUAGE CPP, BangPatterns #-}
 
module Main where
 
import Control.DeepSeq
import Data.List
 
ensure :: [Int] -> IO [Int]
ensure xs = xs `deepseq` return xs
 
testList :: [Int]
testList = [1..100] ++ [error "if we get here, the whole list is evaluated"]
 
main :: IO ()
main = do
!r <- ensure testList
putStrLn "we survived without evaluating r"
let x = foldl' (+) 0 $ take 50 r
putStrLn $ "x was " ++ show x
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.