mirror of
https://github.com/ilyakooo0/Idris-dev.git
synced 2024-11-13 07:26:59 +03:00
5da0d60564
Mostly by delaying the expensive checking for uniqueness of names until the point where we actually need the branch, thus removing a significant amount of unnecesary work.
38 lines
1.0 KiB
Idris
38 lines
1.0 KiB
Idris
import IOu
|
|
|
|
data DoorState = OPEN | CLOSED
|
|
|
|
data DoorH : DoorState -> UniqueType where
|
|
MkDH : DoorH s
|
|
|
|
infix 5 @@
|
|
|
|
data Res : (a : AnyType) -> (a -> AnyType) -> AnyType where
|
|
(@@) : (val : a) -> (h : k val) -> Res a k
|
|
|
|
data DoorCmd : AnyType -> AnyType where
|
|
Open : DoorH CLOSED ->
|
|
DoorCmd (Res Bool (\ok => case ok of
|
|
True => DoorH OPEN
|
|
False => DoorH CLOSED))
|
|
Knock : DoorH CLOSED -> DoorCmd (DoorH CLOSED)
|
|
Close : DoorH OPEN -> DoorCmd (DoorH CLOSED)
|
|
|
|
data DoorLang : AnyType -> AnyType where
|
|
Return : a -> DoorLang a
|
|
Action : DoorCmd a -> DoorLang a
|
|
(>>=) : DoorLang a -> (a -> DoorLang b) -> DoorLang b
|
|
|
|
implicit
|
|
action : DoorCmd a -> DoorLang a
|
|
action = Action
|
|
|
|
covering
|
|
testProg : DoorH CLOSED -> DoorLang ()
|
|
testProg h = do h <- Action (Knock h)
|
|
(True @@ h) <- Action (Open h)
|
|
| (False @@ h) => testProg h
|
|
h <- Action (Close h)
|
|
Return ()
|
|
|