-
-
Save Taneb/c3989dfc6d86f3b0a150 to your computer and use it in GitHub Desktop.
A quine in Haskell
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
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