agda / agda-stdlib

The Agda standard library

Home Page:https://wiki.portal.chalmers.se/agda/Libraries/StandardLibrary

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tidying up `Data.Digit`

jamesmckinna opened this issue · comments

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...