3

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?

Michael Hewson
  • 1,444
  • 13
  • 21
  • You could design a very lightweight preprocessor which allows you to use simple abbreviations which are replaced by their values prior to compiling. – John Coleman Feb 02 '17 at 17:54

1 Answers1

3

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).

Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72