Readit News logoReadit News
sumeetdas commented on PHP 8.5 adds pipe operator   thephp.foundation/blog/20... · Posted by u/lemper
sumeetdas · 22 days ago
The first typed programming language where I've seen pipe operator |> in action was in F#. You can write something like:

  sum 1 2
  |> multiply 3

and it works because |> pushes the output of the left expression as the last parameter into the right-hand function. multiply has to be defined as:

  let multiply b c = b \* c

so that b becomes 3, and c receives the result of sum 1 2.

RHS can also be a lambda too:

  sum 1 2 |> (fun x -> multiply 3 x)

|> is not a syntactic sugar but is actually defined in the standard library as:

  let (|>) x f = f x

For function composition, F# provides >> (forward composition) and << (backward composition), defined respectively as:

  let (>>) f g x = g (f x)
  let (<<) f g x = f (g x)

We can use them to build reusable composed functions:

  let add1 x = x + 1
  let multiply2 x = x \* 2
  let composed = add1 >> multiply2 

F# is a beautiful language. Sad that M$ stopped investing into this language long back and there's not much interest in (typed) functional programming languages in general.

sumeetdas commented on FUML – a new data serialization language based on type theory   github.com/sumeetdas/fuml... · Posted by u/sumeetdas
usrbinbash · 4 years ago
What's the advantage over JSON or YAML?
sumeetdas · 4 years ago
- Its based on type theory, and thus supports data types like tuples, records, and sum types. Those are explained in the specs.

- Does not use quotes to describe property names. Has a unique syntax for large property names.

- It allows for setting a nested property value directly.

- Its also a language to describe the data schema.

- Its syntax is similar to F# and OCaml, so users with some background in functional programming languages should feel it easy to work with.

u/sumeetdas

KarmaCake day34December 26, 2018View Original