Created
October 19, 2011 19:20
-
-
Save gregorycollins/1299380 to your computer and use it in GitHub Desktop.
Evaluation, bang patterns, and deepseq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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