Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Rational numbers

$
0
0

There is a hidden feature in ReScript that allows you to overload the basic arithmetic operators.

You can add an Infix module to your Rational library and overload them like this:

// In Rational.res
module Infix = {
  let \"+" = add
  let \"/" = make
}

then use them like this:

open! Rational.Infix

let a = 6 / 8
let b = 1 / 4
let c = a + b

Playground link

Not sure if it makes fully sense though but you get the point.


Viewing all articles
Browse latest Browse all 2592

Trending Articles