Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Evaluation, bang patterns, and deepseq
{-# 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.