Search code examples
smlsmlnj

In SML, is it possible to define an alias for a pattern?


Let's say I have the following datatype

datatype mytype = Foo | Bar | Baz

and want to write a function like the following

fun myfun ((Foo|Bar), (Foo|Bar)) = something
|   myfun (Baz, _) = somethingelse
|   ...

Is there a way to create an alias for the pattern Foo|Bar, so that I can write it out once and avoid repeating myself?


Solution

  • The answer is plain "no", unfortunately. The notion of "abstract patterns" or "views" has been suggested many times, but it is a tricky space, and no proposal has ever been fully satisfying (and that applies to other languages like Ocaml or Haskell as well).