Created
May 8, 2020 15:08
-
-
Save jvdp/cc0b2c281914bedcb160dc2fa5062fb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let lessThan = https://prelude.dhall-lang.org/Natural/lessThan | |
let stepper = ./stepper.dhall | |
in stepper.askText | |
"What is your name?" | |
( λ(name : Text) | |
→ stepper.askNatural | |
"How old are you?" | |
( λ(age : Natural) | |
→ let advice = | |
if lessThan age 12 | |
then "go play outside!" | |
else "stay inside!" | |
in stepper.end "Hi ${name}, ${advice}" | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let Step | |
: Type | |
= ∀(Step : Type) | |
→ ∀(Final : Text → Step) | |
→ ∀(AskText : Text → (Text → Step) → Step) | |
→ ∀(AskNatural : Text → (Natural → Step) → Step) | |
→ Step | |
let requestOf | |
: Step → Optional Text | |
= λ(stepper : Step) | |
→ stepper | |
(Optional Text) | |
(λ(_ : Text) → None Text) | |
(λ(req : Text) → λ(_ : Text → Optional Text) → Some req) | |
(λ(req : Text) → λ(_ : Natural → Optional Text) → Some req) | |
let resultOf | |
: Step → Optional Text | |
= λ(stepper : Step) | |
→ stepper | |
(Optional Text) | |
(λ(result : Text) → Some result) | |
(λ(req : Text) → λ(_ : Text → Optional Text) → None Text) | |
(λ(req : Text) → λ(_ : Natural → Optional Text) → None Text) | |
let askText | |
: Text → (Text → Step) → Step | |
= λ(req : Text) | |
→ λ(handler : Text → Step) | |
→ λ(Step : Type) | |
→ λ(Final : Text → Step) | |
→ λ(AskText : Text → (Text → Step) → Step) | |
→ λ(AskNatural : Text → (Natural → Step) → Step) | |
→ AskText | |
req | |
(λ(resp : Text) → handler resp Step Final AskText AskNatural) | |
let askNatural | |
: Text → (Natural → Step) → Step | |
= λ(req : Text) | |
→ λ(handler : Natural → Step) | |
→ λ(Step : Type) | |
→ λ(Final : Text → Step) | |
→ λ(AskText : Text → (Text → Step) → Step) | |
→ λ(AskNatural : Text → (Natural → Step) → Step) | |
→ AskNatural | |
req | |
(λ(resp : Natural) → handler resp Step Final AskText AskNatural) | |
let end | |
: Text → Step | |
= λ(result : Text) | |
→ λ(Step : Type) | |
→ λ(Final : Text → Step) | |
→ λ(AskText : Text → (Text → Step) → Step) | |
→ λ(AskNatural : Text → (Natural → Step) → Step) | |
→ Final result | |
let answerText | |
: Step → Text → Step | |
= λ(step : Step) | |
→ λ(resp : Text) | |
→ λ(Step : Type) | |
→ λ(Final : Text → Step) | |
→ λ(AskText : Text → (Text → Step) → Step) | |
→ λ(AskNatural : Text → (Natural → Step) → Step) | |
→ ( step | |
{ head : Step, tail : Step } | |
(λ(result : Text) → { head = Final result, tail = Final result }) | |
( λ(req : Text) | |
→ λ(handler : Text → { head : Step, tail : Step }) | |
→ { head = (handler resp).tail | |
, tail = AskText req (λ(resp : Text) → (handler resp).tail) | |
} | |
) | |
( λ(req : Text) | |
→ λ(handler : Natural → { head : Step, tail : Step }) | |
→ { head = | |
AskNatural req (λ(resp : Natural) → (handler resp).tail) | |
, tail = | |
AskNatural req (λ(resp : Natural) → (handler resp).tail) | |
} | |
) | |
).head | |
let answerNatural | |
: Step → Natural → Step | |
= λ(step : Step) | |
→ λ(resp : Natural) | |
→ λ(Step : Type) | |
→ λ(Final : Text → Step) | |
→ λ(AskText : Text → (Text → Step) → Step) | |
→ λ(AskNatural : Text → (Natural → Step) → Step) | |
→ ( step | |
{ head : Step, tail : Step } | |
(λ(result : Text) → { head = Final result, tail = Final result }) | |
( λ(req : Text) | |
→ λ(handler : Text → { head : Step, tail : Step }) | |
→ { head = AskText req (λ(resp : Text) → (handler resp).tail) | |
, tail = AskText req (λ(resp : Text) → (handler resp).tail) | |
} | |
) | |
( λ(req : Text) | |
→ λ(handler : Natural → { head : Step, tail : Step }) | |
→ { head = (handler resp).tail | |
, tail = | |
AskNatural req (λ(resp : Natural) → (handler resp).tail) | |
} | |
) | |
).head | |
in { requestOf, resultOf, end, askText, askNatural, answerText, answerNatural } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment