Skip to content

Tidying up Data.Digit #2218

Open
Open

Description

@jamesmckinna

Work on #2182 (see comments there) suggests we should revisit this module and tidy up various things, the to{Nat}Digits function in particular.

Specifically, regarding:

toNatDigits : (base : ℕ) {base≤16 : True (1 ≤? base)} → ℕ → List ℕ
toNatDigits base@(suc zero)    n = replicate n 1
toNatDigits base@(suc (suc _)) n = aux (<-wellFounded-fast n) []
  where
  aux : {n : ℕ} → Acc _<_ n → List ℕ → List ℕ
  aux {zero}        _      xs =  (0 ∷ xs)
  aux {n@(suc _)} (acc wf) xs with does (0 <? n / base)
  ... | false = (n % base) ∷ xs -- n here is already sufficient?
  ... | true  = aux (wf (m/n<m n base sz<ss)) ((n % base) ∷ xs)
  • the precondition {base≤16 : True (1 ≤? base)} is now simply {{NonZero base}};
  • the comment about the false branch in aux: why not simply branch on does (n <? base), noting that in the true branch of such a choice, n % base is already given by n...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions