[Haskell-cafe] A functor for two Peano systems

Anthony Clayden anthony_clayden at clear.net.nz
Mon Apr 5 11:49:34 UTC 2021

> Or am I barking up the completely wrong tree here, i.e., this isn't a
functor issue?

Yes you are barking up the wrong tree/no this isn't a Functor issue.

> create just one generic plus that would handle both the plus :: Int ->
Int -> Int and the plus2 :: MyNum -> MyNum -> MyNum.

A Functor would need to be of the form of a parameterised type. That is,
the `f` in `f a`. Neither `Int` nor `MyNum` are parameterised.

You want a plus-like method that's polymorphic/generic across different
Peano-like numeric representations. IOW you want an overloading. That's
what typeclasses are for:

> class PolyPlus a where polyPlus :: a -> a -> a
> instance PolyPlus Int where polyPlus = plus
> instance PolyPlus MyNum where polyPlus = plus2

(In those instances you could just put the definitions for those
functions/no need to define them separately. BTW both those definitions are
truly horrible non-idiomatic Haskell. Why are you trying to write C code in

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210405/7d8d375a/attachment.html>

More information about the Haskell-Cafe mailing list