fork download
  1. {-# LANGUAGE ExistentialQuantification #-}
  2. {-# LANGUAGE NoMonomorphismRestriction #-}
  3. {-# LANGUAGE BangPatterns #-}
  4.  
  5. import Data.Foldable
  6.  
  7. data Stream a = forall s. Stream (s -> Maybe (a, s)) s
  8.  
  9. instance Foldable Stream where
  10. foldr k z (Stream sf s) = go (sf s)
  11. where
  12. go Nothing = z
  13. go (Just (e, ns)) = e `k` go (sf ns)
  14.  
  15. mysum = foldl' (+) 0
  16.  
  17. n :: Int
  18. n = 100000000
  19.  
  20. x1 = [1..n]
  21. x2 = Stream (\s -> if (s == n + 1) then Nothing else Just (s, s + 1)) 1
  22.  
  23. bestcase :: Int
  24. bestcase = go 1 0 where
  25. go i c = if i == n then c + i else go (i+1) (c+i)
  26.  
  27. --main = print $ bestcase
  28. --main = print $ mysum x1
  29. --main = print $ mysum x2
  30.  
Compilation error #stdin compilation error #stdout 0.29s 6264KB
stdin
Standard input is empty
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )

prog.hs:1:1: The function `main' is not defined in module `Main'
stdout
Standard output is empty