amulet icon indicating copy to clipboard operation
amulet copied to clipboard

Curried constructors

Open SquidDev opened this issue 6 years ago • 1 comments

Instead of passing a tuple or record to constructors, you should be able to create them from multiple fields. This offers several advantages:

  • Operator constructors (and thus better pattern matching)
  • Easier usage of some constructors (no let x :: xs = Cons (x, xs) wrappers), etc...

SquidDev avatar Oct 30 '18 11:10 SquidDev

So one potentially neat thing that CamlP4 does is using and instead of * for constructors. So one might have declare lists like so instead:

type list 'a = 
| Nil
| (::) of 'a and list 'a

Allows us to distinguish between tuples and curried constructors, while not breaking backwards compat (not that that is exactly a concern).

SquidDev avatar Jul 11 '19 13:07 SquidDev