-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts-data-structures.rkt
executable file
·50 lines (37 loc) · 1.08 KB
/
ts-data-structures.rkt
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
#lang racket
(provide (all-defined-out))
; An Expr is one of
; - `(var ,Symbol)
; - `(app ,Expr ,Expr)
; - `(abs ,Symbol ,Type ,Expr)
; - `(if ,Expr ,Expr ,Expr)
; - `(builtin ,Symbol)
; - `true
; - `false
; - `(num ,Integer)
;A Type is one of 'top, 'number, 'true, 'false, Union, Abs
;A Union is (make-union List<Type>)
(struct union (types) #:transparent)
;An Abs is (make-abs Symbol Type Type Prop Prop Any)
(struct abs (var param return latent-pos latent-neg obj) #:transparent)
(define (type? x)
(or (memv x '(top number true false))
(union? x)
(abs? x)))
;A Prop is one of
; - `(: ,Symbol ,Type)
; - `(not ,Prop)
; - `(implies ,Prop ,Prop)
; - `(or ,Prop ...)
; - `(and ,Prop ...)
; - #f
; - #t
; this doesn't thoroughly test for Prop-hood; it just checks what the intention of the thing is.
(define (prop? x)
(or (boolean? x)
(and (pair? x)
(memv (car x) '(: not: implies or and)))))
; An Obj is one of Symbol or #f
;; When we find a type error, we raise a type-exn with a
;; [helpful] error message along.
(struct type-exn (message) #:transparent)