gdritter repos pico-ml-old / master stdlib / Num.pml
master

Tree @master (Download .tar.gz)

Num.pml @masterraw · history · blame

exports
  Add(..)
  Mul(..)
  _+_
  _*_

-- mathematical operations

record IsNumber n = .fromInteger (Int -> n)

record Add n =
  .zero n
  .plus (n -> n -> n)

record Mul n =
  .one   n
  .times (n -> n -> n)

record Sub n =
  .pSubAdd (Add n)
  .sub     (n -> n -> n)

record Div n =
  .pDivMul (Mul n)
  .div     (n -> n -> n)
  .mod     (n -> n -> n)
  .rem     (n -> n -> n)

-- some teaspoons for mathematical operations

fromInteger : implicit (IsNumber n) -> Int -> n
  i = i.fromInteger

_+_ : n -> n -> implicit (Add n) -> n
  x y add = add.plus x y

_*_ : n -> n -> implicit (Mul n) -> n
  x y mul = mul.times x y