You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
app "higher-order"
|
|
|
|
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.7.1/Icc3xJoIixF3hCcfXrDwLCu4wQHtNdPyoJkEbkgIElA.tar.br" }
|
|
|
|
imports [pf.Stdout, pf.Task]
|
|
|
|
provides [main] to pf
|
|
|
|
|
|
|
|
main : Task.Task {} I32
|
|
|
|
main =
|
|
|
|
fn1 = bind Num.sub 3
|
|
|
|
fn2 = bindL Num.mul 3
|
|
|
|
fn3 = compose fn1 fn2
|
|
|
|
fn4 = compose fn2 fn1
|
|
|
|
fn5 = compose (compose fn1 fn2) (compose fn3 fn4)
|
|
|
|
fn6 : F64 -> Int a
|
|
|
|
fn6 =
|
|
|
|
(\n -> n)
|
|
|
|
|> compose Num.sqrt
|
|
|
|
|> compose Num.ceiling
|
|
|
|
results =
|
|
|
|
[fn1 2, fn2 2, fn3 2, fn4 2, fn5 2, fn6 9]
|
|
|
|
|> List.map Num.toStr
|
|
|
|
|> List.mapWithIndex \e, idx -> "fn$(Num.toStr idx) -> $(e)"
|
|
|
|
|> Str.joinWith "\n"
|
|
|
|
Stdout.line "$(results)"
|
|
|
|
|
|
|
|
bind : (a, b -> c), a -> (b -> c)
|
|
|
|
bind = \fn, a ->
|
|
|
|
\b -> fn a b
|
|
|
|
|
|
|
|
bindL : (a, b -> c), b -> (a -> c)
|
|
|
|
bindL = \fn, b ->
|
|
|
|
\a -> fn a b
|
|
|
|
|
|
|
|
compose : (a -> b), (b -> c) -> (a -> c)
|
|
|
|
compose = \fn1, fn2 ->
|
|
|
|
\a -> fn1 a |> fn2
|