summaryrefslogtreecommitdiff
path: root/src/Obs/Syntax.idr
blob: bcc0cb457ff4e689c96f545d202e77be3497b135 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
||| Raw syntax for terms. This is before eliminating names.
module Obs.Syntax

import Obs.Sort
import Text.Bounded
import Text.PrettyPrint.Prettyprinter

%default total

-- Definition ------------------------------------------------------------------

public export
data Syntax : Type where
  Var    : WithBounds String -> Syntax
  -- Sorts
  Sort   : Bounds -> Sort -> Syntax
  -- Dependent Products
  Pi     : Bounds -> WithBounds String -> Syntax -> Syntax -> Syntax
  Lambda : Bounds -> WithBounds String -> Syntax -> Syntax
  App    : Syntax -> Syntax -> Syntax
  -- Dependent Sums
  Sigma  : Bounds -> WithBounds String -> Syntax -> Syntax -> Syntax
  Pair   : Bounds -> Syntax -> Syntax -> Syntax
  Fst    : Bounds -> Syntax -> Syntax
  Snd    : Bounds -> Syntax -> Syntax
  -- True
  Top    : Bounds -> Syntax
  Point  : Bounds -> Syntax
  -- False
  Bottom : Bounds -> Syntax
  Absurd : Bounds -> Syntax -> Syntax -> Syntax
  -- Equality
  Equal  : Bounds -> Syntax -> Syntax -> Syntax
  Refl   : Bounds -> Syntax -> Syntax
  Transp : Bounds -> Syntax -> Syntax -> Syntax -> Syntax -> Syntax -> Syntax
  Cast   : Bounds -> Syntax -> Syntax -> Syntax -> Syntax
  CastId : Bounds -> Syntax -> Syntax

public export
record Definition where
  constructor MkDefinition
  bounds : Bounds -- of the name
  name   : String
  ty     : Syntax
  tm     : Syntax

-- Pretty Print ----------------------------------------------------------------

export
Pretty Syntax where
  prettyPrec d (Var var) = pretty var.val
  prettyPrec d (Sort _ s) = prettyPrec d s
  prettyPrec d (Pi _ var a b) =
    parenthesise (d > Open) $
    group $
    parens (pretty var.val <++> colon <+> softline <+> prettyPrec Open a) <++>
    pretty "->" <+> softline <+>
    prettyPrec Open b
  prettyPrec d (Lambda _ var t) =
    parenthesise (d > Open) $
    group $
    backslash <+> pretty var.val <++>
    pretty "=>" <+> softline <+>
    prettyPrec Open t
  prettyPrec d (App t u) =
    parenthesise (d >= App) $
    group $
    fillSep [prettyPrec Open t, prettyPrec App u]
  prettyPrec d (Sigma _ var a b) =
    parenthesise (d >= App) $
    group $
    parens (pretty var.val <++> colon <+> softline <+> prettyPrec Open a) <++>
    pretty "**" <+> softline <+>
    prettyPrec Open b
  prettyPrec d (Pair _ t u) =
    angles $
    group $
    neutral <++> prettyPrec Open t <+> comma <+> softline <+> prettyPrec Open u <++> neutral
  prettyPrec d (Fst _ t) =
    parenthesise (d >= App) $
    group $
    fillSep [pretty "fst", prettyPrec App t]
  prettyPrec d (Snd _ t) =
    parenthesise (d >= App) $
    group $
    fillSep [pretty "snd", prettyPrec App t]
  prettyPrec d (Top _) = pretty "()"
  prettyPrec d (Point _) = pretty "tt"
  prettyPrec d (Bottom _) = pretty "Void"
  prettyPrec d (Absurd _ a t) =
    parenthesise (d >= App) $
    group $
    fillSep [pretty "absurd", prettyPrec App a, prettyPrec App t]
  prettyPrec d (Equal _ t u) =
    parenthesise (d >= Equal) $
    group $
    prettyPrec Equal t <++> pretty "~" <+> softline <+> prettyPrec Equal u
  prettyPrec d (Refl _ t) =
    parenthesise (d >= App) $
    group $
    fillSep [pretty "refl", prettyPrec App t]
  prettyPrec d (Transp _ t b u t' e) =
    parenthesise (d >= App) $
    group $
    fillSep $
    [ pretty "transp"
    , prettyPrec App t
    , prettyPrec App b
    , prettyPrec App u
    , prettyPrec App t'
    , prettyPrec App e
    ]
  prettyPrec d (Cast _ b e t) =
    parenthesise (d >= App) $
    group $
    fillSep [pretty "cast", prettyPrec App b, prettyPrec App e, prettyPrec App t]
  prettyPrec d (CastId _ t) =
    parenthesise (d >= App) $
    group $
    fillSep [pretty "castRefl", prettyPrec App t]

export
Pretty Definition where
  pretty def = group $
    pretty def.name <++> colon <+> softline <+> pretty def.ty <+> hardline <+>
    pretty def.name <++> equals <+> softline <+> pretty def.tm