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 inaux
: why not simply branch ondoes (n <? base)
, noting that in thetrue
branch of such a choice,n % base
is already given byn
...