-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapter14.1.idr
37 lines (31 loc) · 1.08 KB
/
chapter14.1.idr
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
module Main
import Data.List.Views
import Data.Vect
import Data.Vect.Views
import Data.Nat.Views
import Data.Bits
%default total
namespace Door
data DoorState = DoorClosed | DoorOpen
data DoorResult = OK | Jammed
data DoorCmd : (ty : Type) -> DoorState -> (ty -> DoorState) -> Type where
Open : DoorCmd DoorResult DoorClosed
(\res =>
case res of
OK => DoorOpen
Jammed => DoorClosed
)
Close : DoorCmd () DoorOpen (const DoorClosed)
RingBell : DoorCmd () s (const s)
Display : String -> DoorCmd () state (const state)
Pure : (res : ty) -> DoorCmd ty (state_fn res) state_fn
(>>=) : DoorCmd a state1 state2_fn -> ((res : a) -> DoorCmd b (state2_fn res) state3_fn) -> DoorCmd b state1 state3_fn
doorProg : DoorCmd () DoorClosed (const DoorClosed)
doorProg =
do
RingBell
jam <- Open
case jam of
OK => Close
Jammed => Display "Something bad happened"
RingBell