Skip to content

Commit

Permalink
Better datatype formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomahawkins committed Apr 10, 2012
1 parent 75eecc2 commit 484f798
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Language/CIRC.hs
Expand Up @@ -130,9 +130,10 @@ codeModule initModuleName initImports rootTypeName moduleName unsortedTypes tran

codeTypeDef :: TypeDef -> String
codeTypeDef (TypeDef name params ctors) = "data " ++ name ++ " " ++ intercalate " " params ++ "\n = " ++
intercalate "\n | " [ name ++ " " ++ intercalate " " (map codeType args) | CtorDef name args <- ctors' ] ++ "\n"
intercalate "\n | " [ name ++ replicate (m - length name) ' ' ++ " " ++ intercalate " " (map codeType args) | CtorDef name args <- ctors' ] ++ "\n"
where
ctors' = sortBy (compare `on` \ (CtorDef n _) -> n) ctors
m = maximum [ length n | CtorDef n _ <- ctors ]

codeType :: Type -> String
codeType a = case a of
Expand Down

0 comments on commit 484f798

Please sign in to comment.