Commit 697cefbe authored by marton bognar's avatar marton bognar
Browse files

Add fresh variable generator functions to Haskell printer

parent 4683c896
......@@ -3,8 +3,10 @@
module Printer.Haskell where
import Data.Text.Prettyprint.Doc
import Data.Maybe
import Program
import Utility
import GeneralTerms
instance Pretty Constructor where
pretty (Constr n ts) = hsep (pretty (upperFirst n) : map pretty ts)
......@@ -46,6 +48,7 @@ printProgram name program =
printImports (("Data.List", []) : imports program),
printTypeDecls (types program),
nl,
freshVarFunctions (types program),
printFunctions (functions program),
printInstances (instances program),
printCode (code program)
......@@ -91,3 +94,11 @@ printInstances ids = intoLines $ map (
printCode :: [String] -> Doc String
printCode lns = intoLines $ map pretty lns
freshVarFunctions :: [(Type, [Constructor])] -> Doc String
freshVarFunctions types
= let ctors = fromJust (lookup "Variable" types)
names = map (\(Constr name _) -> tail name) ctors
in intoLines [
pretty ("fresh" ++ name ++ " x b = if not (x `elem` b) then x else head [S" ++ name ++ " ('v' : show n) | n <- [0..], not (S" ++ name ++ " ('v' : show n) `elem` b)]")
| name <- names]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment