Skip to content

[ refactor ] a 'better' Data.Integer.Base? #2879

Description

@jamesmckinna

I was experimenting with Integers, leading to agda/agda#8208 (so I don't see this going anywhere anytime soon, but the coupling between 'primitive's and Builtins looks as though it might benefit from a closer look?), towards defining instead:

{-# OPTIONS --cubical-compatible --safe #-}

module Data.Integer.Base where

open import Data.Nat.Base as ℕ using (ℕ) hiding (module )

------------------------------------------------------------------------
-- Integers: add `NonZero` as a premise to the `negsuc` constructor

data  : Set where
  pos :  (n : ℕ) neg :  (n : ℕ)  ℕ.NonZero n pattern negsuc n = neg (ℕ.suc n) _

{-# BUILTIN INTEGER       ℤ    #-}
{-# BUILTIN INTEGERPOS    pos    #-}

and then most/all of the gymnastics associated with -[1+ n ] etc. ought to go away, which I think would be better for (user and developer intelligibility), esp. eg. #2878 because the Signed representation then becomes ... almost automatic.

NB. Again, for 'reasons', we can't define

data  : Set where
  pos :  (n : ℕ) neg :  (n : ℕ)  {{ℕ.NonZero n}} 

but in view of #2644 maybe making the proof explicit (but being able to finesse it via the negsuc pattern synonym where needed) isn't such a bad thing...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions