Created
September 16, 2017 12:43
-
-
Save Dierk/0f7c90df5267be7d2b57c004588b0b65 to your computer and use it in GitHub Desktop.
example of a possible space leak in lazy languages like Frege when running on a platform like JVM
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
-- Leak example from http://homepages.inf.ed.ac.uk/wadler/papers/leak/leak.ps | |
-- convenience | |
parseStr :: String -> (String, String) | |
parseStr = packedPair . parse . unpacked where | |
packedPair (x,y) = (packed x, packed y) | |
parse :: [Char] -> ([Char], [Char]) | |
parse [] = ([], []) | |
parse (' ': cs) = ([], cs) | |
parse ( c : cs) = ( c : fst b, snd b) where | |
b = parse cs | |
surprise :: String -> String | |
surprise s = fst p ++ " surprise " ++ snd p where | |
p = parseStr s | |
main _ = do | |
println $ parseStr "first next last" == ("first", "next last") | |
println $ surprise "first next last" == "first surprise next last" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment