amuletml / amulet

An ML-like functional programming language
https://amulet.works/
BSD 3-Clause "New" or "Revised" License
324 stars 14 forks source link

How to define custom math operators for types? #289

Closed s5bug closed 3 years ago

s5bug commented 3 years ago

Trying to define a custom infix operator that starts with a * throws an error because (* starts a comment.

It may be useful to look at https://typelevel.org/spire/guide.html for amulet so that (+) : semiring 'a => 'a -> 'a -> 'a, what I want to use amulet for partly revolves around making custom number types so typeclasses for those things would be useful.

SquidDev commented 3 years ago

The "solution" here is slightly silly, but also standard practice in OCaml/ML world - just add spaces and use ( * ) instead.

I think we've intentionally kept the numeric tower quite short for now. The prelude is intentionally pretty minimal. Of course, it's pretty easy to swap out for your own.