-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.archetype
49 lines (41 loc) · 1.38 KB
/
example.archetype
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
-- Non-empty list
prim type NonEmpty : ∀(a : Type) → NonEmpty a
-- [Universally unique identifier
-- ](https://en.wikipedia.org/wiki/Universally_unique_identifier)
prim type UUID : Type
-- REST and RPC calls are modeled as primitive types as well. This allows us
-- to support any transport layer supported by individual code generator.
prim type RpcCall
: ∀(request : Type)
→ ∀(response : Type)
→ RpcCall request response
-- Every user account can be identified by a unique UUID.
type UserId = UUID
-- Enums are supported as a special case of sum types.
type UserRole = < Admin | NormalUser >
-- A user, what a surprise.
type User =
{ id : UserId
, full-name : Text
, emails : NonEmpty Text
, verified : Bool
, role : UserRole
}
type GetUserError =
< NoSuchUser
| AccountDisabled
| OtherError : Text
>
-- We can define polymorphic types. Code generators may need to make them
-- monomorphic when generating code for languages that do not support them.
-- That can be achieved by requiring top-level type (usually RPC or REST call)
-- to be present. For those the polymorphic types need to be fully applied,
-- therefore, code generator can define something like `GetUserResponse`
-- instead.
type Response =
λ(error : Type)
→ λ(r : Type)
→ < Error : error
| Response : r
>
type rpc-get-user = RpcCall UserId (Response GetUserError User)