Created
December 2, 2021 03:46
-
-
Save yanns/3212cd6400b6ccf0f32912e1c96e9b1f 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
app "cli-tutorial" | |
packages { pf: "../examples/cli/platform" } | |
imports [ pf.Stdout, pf.Task.{ await } ] | |
provides [ main ] to pf | |
Option a : [ Some a, None ]a | |
Aggr : { counts: Nat, previousElement: Option Nat} | |
initialState: Aggr | |
initialState = { counts: 0, previousElement: None } | |
walkStep: Aggr, Nat -> Aggr | |
walkStep = \state, elem -> | |
when state.previousElement is | |
Some previousElement if previousElement < elem -> { counts: state.counts + 1, previousElement: Some elem } | |
_ -> { state & previousElement: Some elem } | |
measurements : List Nat | |
measurements = [199, 200, 208, 210, 200, 207, 240, 269, 260, 263 ] | |
increases: Aggr | |
increases = List.walk measurements initialState walkStep | |
increasesStr = Num.toStr increases.counts | |
main = | |
{} <- await (Stdout.line "There are \(increasesStr) increases") | |
Task.succeed {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment