Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlap between function heads and match expression #235

Open
lpil opened this issue Jan 12, 2018 · 1 comment
Open

Overlap between function heads and match expression #235

lpil opened this issue Jan 12, 2018 · 1 comment

Comments

@lpil
Copy link
Contributor

lpil commented Jan 12, 2018

Hello!

One thing that Alpaca has inherited from Erlang is the ability to write multiple function heads and use pattern matching to select the one that runs for given arguments.

val say : fn int -> string
let say 1 =
  "one"

let say 2 =
  "two"

let say _ =
  "dunno"

This serves the same purpose as the match expression.

val say : fn int -> string
let say n =
  match n with
  | 1 -> "one"
  | 2 -> "two"
  | _ -> "dunno"

Perhaps a question about the philosophy of the Alpaca language, but do we want both constructs when they serve the same purpose?

It would be my preference for there to a single way to express anything in the language as this reduces inconsistency in code written in the language, and also makes the language more approachable by reducing the number of things for newcomers to learn.

Thanks,
Louis

@j14159
Copy link
Collaborator

j14159 commented Jan 13, 2018

Perhaps a question about the philosophy of the Alpaca language, but do we want both constructs when they serve the same purpose?

At present the existence of both is deliberate. match existed before function head matching which also got added because I missed having it :) In general I prefer function head matching but I think that it can get a little unwieldy sometimes and it can be cleaner to fall back to a match. It's also consistent in form with the syntax used by receive and beam so I think there's enough similarity there to warrant keeping it around.

Having said that, I'm not 100% opposed to trying out deprecating/removing match as an experiment at some point in the future but:

  • it would require local functions/bindings to support function head matching and we might want some syntax changes to make this more pleasant.
  • I think it would make us a little less consistent with other MLs (e.g. OCaml).
  • I would like us to take a pretty careful look at how this changes the ergonomics of the language. This might get pretty subjective in some corners but I'd like to hear from a relatively wide cross-section of our (still relatively small) community.

I don't know if this is a good solution/something worth trying: a compiler flag that disables match, similar to the possible "decidability" flag that has been discussed elsewhere (would rule type a = int | float a type error).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants