alpaca-lang / alpaca

Functional programming inspired by ML for the Erlang VM
Other
1.44k stars 46 forks source link

Multi-head lambdas #138

Closed j14159 closed 7 years ago

j14159 commented 7 years ago

Per discussion on PR #135 I think we should probably add simple multi-head lambdas in the vein of OCaml for single-argument lambdas. Example of the potential syntax based on the discussion so far:

fn
    0 -> :zero 
  | 1 -> :one 
  | _ -> :something_else

We'll likely want to make guards available here as well. This should be pretty easy to parse, likely requires minimal changes to AST generation, and requires no changes for the typer and code generation.

Additional feedback, comments, and suggestions all welcome.

j14159 commented 7 years ago

Just a thought, we might want to make | optional for the first clause rather than requiring its absence, e.g.

fn
    x -> ...
  | y -> ...

and

fn
  | x -> ...
  | y -> ...

should maybe both just work with the same changes applied for pattern matches, etc.

OvermindDL1 commented 7 years ago

The first | is optional in OCaml for comparison, in match as well.

j14159 commented 7 years ago

Yeah, I think it might make sense to do the same in Alpaca - a little simpler to line things up.