The mono-traversable package uses type level Peano numbers for MinLen. I can construct them using chained Succs:
toMinLen [1,2,3] :: Maybe (MinLen (Succ (Succ Zero)) [Int])
but this quickly gets out of hand:
toMinLen [1,2,3] :: Maybe (MinLen (Succ (Succ (Succ (Succ (Succ Zero))))) [Int])
Is there a convenient way to construct larger Peano numbers? I see GHC has a TypeLiterals extension but I'm not sure if I can use it here. Alternatively, I can make synonyms like:
type One = Succ Zero
type Two = Succ One
and so on; does something like that already exist somewhere?
TypeLitsis perfectly good for type-level numerals. Also, it's easy to use it only for syntactic sugar and leave the underlying library-specific implementation unchanged.We have to define a type family that converts a literal to the number type:
Now you can use
Lit nwhenever you need aNatliteral. In GHCi: