[Haskell-cafe] A functor for two Peano systems

Olaf Klinke olf at aatal-apotheke.de
Mon Apr 5 19:57:23 UTC 2021


You should try to

1. destill which basic operations are necessary on the types Int, 
MyNum to make your algorithms work,
2. write a type class for these operations,
3. write type class instances for Int and MyNum,
4. write a generic algorithm that works for all members your class, which 
ideally looks almost identical to the specific code you already have.

I dare say this is a common way of reducing boilerplate code in Haskell.
BTW, you should consider Numeric.Natural instead of Int for Peano 
addition.

Cheers
Olaf


More information about the Haskell-Cafe mailing list