summaryrefslogtreecommitdiff
path: root/src/Obs/Term.idr
blob: 05b9a7f88edec3a5688f64f0dec35e4596d02dc0 (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
||| Abstract syntax for terms.
module Obs.Term

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

%default total

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

public export
data Term : Nat -> Type where
  Var    : Bounds -> Fin n -> Term n
  -- Sorts
  Sort   : Bounds -> Sort -> Term n
  -- True
  Top    : Bounds -> Term n
  Point  : Bounds -> Term n
  -- False
  Bottom : Bounds -> Term n
  Absurd : Bounds -> Term n -> Term n -> Term n

public export
record Definition (n : Nat) where
  constructor MkDefinition
  bounds : Bounds -- of the name
  name   : String
  ty     : Term n
  tm     : Term n

public export
data Block : Nat -> Type where
  Nil  : Block 0
  (:<) : Block n -> Definition n -> Block (S n)

-- Operations ------------------------------------------------------------------

export
fullBounds : Term n -> WithBounds (Term n)
fullBounds tm@(Var x i)      = MkBounded tm False x
fullBounds tm@(Sort x s)     = MkBounded tm False x
fullBounds tm@(Top x)        = MkBounded tm False x
fullBounds tm@(Point x)      = MkBounded tm False x
fullBounds tm@(Bottom x)     = MkBounded tm False x
fullBounds tm@(Absurd x a t) = mergeBounds (mergeBounds (fullBounds a) (fullBounds t)) (MkBounded tm False x)

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

export
Pretty (Term n) where
  prettyPrec d (Var x i) = pretty "$\{show i}"
  prettyPrec d (Sort x s) = prettyPrec d s
  prettyPrec d (Top x) = pretty "()"
  prettyPrec d (Point x) = pretty "*"
  prettyPrec d (Bottom x) = pretty "Void"
  prettyPrec d (Absurd x a t) =
    parenthesise (d > Open) $
    group $
    fillSep [pretty "absurd", prettyPrec App a, prettyPrec App t]

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

export
Pretty (Block n) where
  pretty []           = neutral
  pretty ([] :< def)  = pretty def
  pretty (blk :< def) = pretty blk <+> hardline <+> hardline <+> pretty def