@@ -1,3 +1,4 @@
1+{-# OPTIONS_GHC -Wall #-}
12module SourceSyntax.Type where
23
34import Data.Binary
@@ -31,7 +32,7 @@ tupleOf ts = Data ("_Tuple" ++ show (length ts)) ts
3132instance Pretty Type where
3233 pretty tipe =
3334 case tipe of
34− Lambda t1 t2 -> P.sep [ t, P.sep (map (P.text "->" <+>) ts) ]
35+ Lambda _ _ -> P.sep [ t, P.sep (map (P.text "->" <+>) ts) ]
3536 where t:ts = collectLambdas tipe
3637 Var x -> P.text x
3738 Data "_List" [t] -> P.brackets (pretty t)
@@ -47,12 +48,14 @@ instance Pretty Type where
4748 prettyField (f,t) = P.text f <+> P.text ":" <+> pretty t
4849 prettyFields = commaSep . map prettyField $ fields
4950
51+collectLambdas :: Type -> [Doc]
5052collectLambdas tipe =
5153 case tipe of
5254 Lambda arg@(Lambda _ _) body -> P.parens (pretty arg) : collectLambdas body
5355 Lambda arg body -> pretty arg : collectLambdas body
5456 _ -> [pretty tipe]
5557
58+collectRecords :: Type -> ([(String,Type)], Type)
5659collectRecords = go []
5760 where
5861 go fields tipe =
@@ -60,6 +63,7 @@ collectRecords = go []
6063 Record fs ext -> go (fs ++ fields) ext
6164 _ -> (fields, tipe)
6265
66+prettyParens :: Type -> Doc
6367prettyParens tipe = parensIf needed (pretty tipe)
6468 where
6569 needed =