programming_languages/sml/week3/operators.sml

21 lines
400 B
Standard ML
Raw Permalink Normal View History

2020-06-02 03:39:00 +03:00
(*
Pipe operator.
Simply to write code like "data |> fun" instead "fun data".
Then you can "pipe" results to functions via partial application:
fun square a b = a * b
fun sum a b = a + b
10 |> sum 10 |> square 2 // 40
*)
fun |> (x, f) = f x
2020-06-02 23:34:23 +03:00
(* apply operator *)
2020-06-02 03:39:00 +03:00
fun $ (f, x) = f x
2020-06-02 23:34:23 +03:00
(* composition operator *)
fun >> (f, g) x = g(f(x))
2020-06-02 03:39:00 +03:00
infix |>
2020-06-02 23:34:23 +03:00
infix $
infix >>