leostera / caramel

:candy: a functional language for building type-safe, scalable, and maintainable applications
https://caramel.run
Apache License 2.0
1.05k stars 25 forks source link

Support aliases in patterns #83

Closed michallepicki closed 3 years ago

michallepicki commented 3 years ago

http://caml.inria.fr/pub/docs/manual-ocaml/patterns.html#sss:pat-alias

It should translate to Alias = pat in Erlang.

https://github.com/AbstractMachinesLab/caramel/blob/d5128fce81b08a8007729f4c60f03297a8aa4b20/caramel/compiler/ocaml_to_erlang/fun.ml#L101

Example:

 let with_alias ([ x ] as l) = if x then l else []

should translate to

  -spec with_alias(list(boolean())) -> list(boolean()).
  with_alias([X | []] = L) ->
    case X of
      true -> L;
      false -> []
    end.