Skip to content

Instantly share code, notes, and snippets.

@Dierk
Created September 16, 2017 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dierk/0f7c90df5267be7d2b57c004588b0b65 to your computer and use it in GitHub Desktop.
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
-- 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