on 8a87749 help sign in
elk/src/AST/Expression/Valid.hs
43 lines 1.1 kB history raw
1{-# OPTIONS_GHC -Wall #-}
3module AST.Expression.Valid where
5import AST.PrettyPrint
6import Text.PrettyPrint as P
7import qualified AST.Expression.General as General
8import AST.Type (RawType)
9import qualified AST.Variable as Var
10import qualified AST.Annotation as Annotation
11import qualified AST.Pattern as Pattern
14{-| "Normal" expressions. When the compiler checks that type annotations and
15ports are all paired with definitions in the appropriate order, it collapses
16them into a Def that is easier to work with in later phases of compilation.
17-}
18type Expr =
19 General.Expr Annotation.Region Def Var.Raw
22type Expr' =
23 General.Expr' Annotation.Region Def Var.Raw
26data Def = Definition Pattern.RawPattern Expr (Maybe RawType)
27 deriving (Show)
30instance Pretty Def where
31 pretty (Definition pattern expr maybeTipe) =
32 P.vcat [ annotation, definition ]
33 where
34 definition =
35 pretty pattern <+> P.equals <+> pretty expr
37 annotation =
38 case maybeTipe of
39 Nothing ->
40 P.empty
42 Just tipe ->
43 pretty pattern <+> P.colon <+> pretty tipe