Skip to content

Instantly share code, notes, and snippets.

@Taneb
Created February 27, 2015 22:10
Show Gist options
  • Save Taneb/c3989dfc6d86f3b0a150 to your computer and use it in GitHub Desktop.
Save Taneb/c3989dfc6d86f3b0a150 to your computer and use it in GitHub Desktop.
A quine in Haskell
module Main where
a, b :: String
a = "module Main where\n\na, b :: String\na = \""
b = "\"\n\nexpand :: Char -> String\nexpand '\\n' = \"\\\\n\"\nexpand '\"' = \"\\\\\\\"\"\nexpand '\\\\' = \"\\\\\\\\\"\nexpand c = [c]\n\nmain :: IO ()\nmain = do\n putStr a\n putStr $ a >>= expand\n putStr \"\\\"\\nb = \\\"\"\n putStr $ b >>= expand\n putStr b\n"
expand :: Char -> String
expand '\n' = "\\n"
expand '"' = "\\\""
expand '\\' = "\\\\"
expand c = [c]
main :: IO ()
main = do
putStr a
putStr $ a >>= expand
putStr "\"\nb = \""
putStr $ b >>= expand
putStr b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment