As @Rasko noted in the answer, a space leak refers to a situation where a program or a particular calculation uses more (usually much more) memory than is necessary for the calculation and / or expected by the programmer.
Haskell, , , - ( , IO ) , , .
. Haskell:
main = print $ sum [1..1000000000]
. -O2, ( , , ).
, , , , , Haskell . , , , , ( , Haskell).
, , , - , , , , , . , "" - , . (, , : , .)
Soooo... Haskell , ( ) " " , .
, , , :
main = let vals = [1..1000000000]
in print (sum vals, length vals)
, (, , 13Gigs, , ).
. - , , , , " " , , . , , vals, , "" . sum vals, , , length vals .
:
main = do txt <- getContents
print (length txt, length (words txt))
, 10- , 100 , , . , , - txt - txt , Haskell String ( ), , , length txt , , length (words txt).
, :
main = do txt <- getContents
print $ length txt
main = do txt <- getContents
print $ length (words txt)
.
, , , , , , . :
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Char
charsWords :: String -> (Int, Int)
charsWords str = let (_, chrs, wrds) = foldl' step (False, 0, 0) str
in (chrs, wrds)
where step (inWord, cs, ws) c =
let !cs' = succ cs
in (inWord', cs', ws')
main = do txt <- getContents
print $ charsWords txt
( bang (!) length words) , , Haskell. , foldl' foldl ( foldr foldr' !), cs' ws' , inWord' ( ) ..