47 lines
1.4 KiB
Plaintext
47 lines
1.4 KiB
Plaintext
# idk
|
|
|
|
basic stuff.
|
|
don't like haskell's reverse order of applying operations inside out, makes code hard to read.
|
|
piping >>
|
|
|
|
// this would be the syntax to filter a list of numbers to get the evens
|
|
evens x List(Int) => x
|
|
|> filter_map (div 2 |> equals 0)
|
|
|
|
// similarly you can use lambdas (same syntax as ordinary functions)
|
|
evens x List(Int) => x
|
|
|> filter_map (x => div 2 |> equals 0)
|
|
|
|
is_even x Int => x |> div 2 |> equals 0
|
|
|
|
add_y_if_even_else_z x Int, y Int, z Int => x
|
|
|> is_even
|
|
|> then (add y)
|
|
|> else (add z)
|
|
|
|
then Bool x, (-> T) val -> Option(T) =>
|
|
// language internal
|
|
|
|
else Option(T) val (-> T) alternative -> T =>
|
|
// language internal
|
|
|
|
type Result(T, E) => Ok(T) | Err(E)
|
|
type Option(T) => Some(T) | None
|
|
type Shape => Square(Int) | Rectangle(Int, Int) | Circle(Int)
|
|
|
|
// we can pattern match
|
|
area_doubled Shape s -> Int => s
|
|
|> case Square (s => multiply s s)
|
|
|> case Rectangle multiply // multiply takes two integer arguments and Rectangle provides this!
|
|
|> case Circle (r => multiply r r |> multiply PI)
|
|
|> case Circle (r => r |> multiply r |> multiply PI)
|
|
|> case Circle (r => r, r |> multiply |> multiply PI)
|
|
|> case Circle (r => r, r |> (multiply >> multiply PI))
|
|
|> multiply 2
|
|
|
|
chained_computation Int s -> Result(Int, ErrType) => s
|
|
|> try fallible_computation_on_int
|
|
|> try fallible_computation_on_int
|
|
|
|
case T item, T matched_variant, (-> R) -> Option(R) =>
|
|
// language internal |