@@ -1,3 +1,4 @@
1+{-# OPTIONS_GHC -Wall #-}
1module SourceSyntax.Type where
2module SourceSyntax.Type where
3import Data.Binary
4import Data.Binary
@@ -31,7 +32,7 @@ tupleOf ts = Data ("_Tuple" ++ show (length ts)) ts
31instance Pretty Type where
32instance Pretty Type where
32 pretty tipe =
33 pretty tipe =
33 case tipe of
34 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) ]
35 where t:ts = collectLambdas tipe
36 where t:ts = collectLambdas tipe
36 Var x -> P.text x
37 Var x -> P.text x
37 Data "_List" [t] -> P.brackets (pretty t)
38 Data "_List" [t] -> P.brackets (pretty t)
@@ -47,12 +48,14 @@ instance Pretty Type where
47 prettyField (f,t) = P.text f <+> P.text ":" <+> pretty t
48 prettyField (f,t) = P.text f <+> P.text ":" <+> pretty t
48 prettyFields = commaSep . map prettyField $ fields
49 prettyFields = commaSep . map prettyField $ fields
51+collectLambdas :: Type -> [Doc]
50collectLambdas tipe =
52collectLambdas tipe =
51 case tipe of
53 case tipe of
52 Lambda arg@(Lambda _ _) body -> P.parens (pretty arg) : collectLambdas body
54 Lambda arg@(Lambda _ _) body -> P.parens (pretty arg) : collectLambdas body
53 Lambda arg body -> pretty arg : collectLambdas body
55 Lambda arg body -> pretty arg : collectLambdas body
54 _ -> [pretty tipe]
56 _ -> [pretty tipe]
58+collectRecords :: Type -> ([(String,Type)], Type)
56collectRecords = go []
59collectRecords = go []
58 go fields tipe =
61 go fields tipe =
@@ -60,6 +63,7 @@ collectRecords = go []
60 Record fs ext -> go (fs ++ fields) ext
63 Record fs ext -> go (fs ++ fields) ext
61 _ -> (fields, tipe)
64 _ -> (fields, tipe)
66+prettyParens :: Type -> Doc
63prettyParens tipe = parensIf needed (pretty tipe)
67prettyParens tipe = parensIf needed (pretty tipe)