Skip to content

Instantly share code, notes, and snippets.

@ldfallas
Created February 1, 2012 13:02
Show Gist options
  • Save ldfallas/1716897 to your computer and use it in GitHub Desktop.
Save ldfallas/1716897 to your computer and use it in GitHub Desktop.
data Expr = ScSymbol String
| ScString String
| ScNumber Integer
| ScDouble Double
| ScCons Expr Expr
| ScNil
| ScBool Bool
| ScQuote Expr
deriving Show
toString :: Expr -> String
toString (ScSymbol name) = name
toString (ScNumber num) = show num
toString (ScDouble num) = show num
toString ScNil = "'()"
toString (ScQuote exp) = "'" ++ (toString exp)
toString (ScBool value) = if value then "#t" else "#f"
toString (ScString str) = "\"" ++ str ++ "\""
toString (ScCons first rest) = "(" ++ (toString first) ++ (toStringCons rest)
toStringCons (ScCons part rest) = " " ++ (toString part) ++ toStringCons rest
toStringCons ScNil = ")"
toStringCons other = "." ++ (toString other) ++ ")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment