module Prim.Literals where

Primitive: Overloaded literalsπŸ”—

We define the records Number, Negative and String to allow overloading of the numeric literals.

record Number {a} (A : Type a) : Type (lsuc a) where
  field
    Constraint : Nat β†’ Type a
    fromNat : βˆ€ n β†’ {{_ : Constraint n}} β†’ A

open Number {{...}} public using (fromNat)

record Negative {a} (A : Type a) : Type (lsuc a) where
  field
    Constraint : Nat β†’ Type a
    fromNeg : βˆ€ n β†’ {{_ : Constraint n}} β†’ A

open Negative {{...}} public using (fromNeg)

{-# BUILTIN FROMNAT fromNat #-}
{-# DISPLAY Number.fromNat _ n = fromNat n #-}
{-# BUILTIN FROMNEG fromNeg #-}
{-# DISPLAY Negative.fromNeg _ n = fromNeg n #-}

{-# DISPLAY Number.fromNat _ n = fromNat n #-}
{-# DISPLAY Negative.fromNeg _ n = fromNeg n #-}

instance
  Number-Nat : Number Nat
  Number-Nat .Number.Constraint _ = ⊀
  Number-Nat .Number.fromNat n = n