[Haskell-cafe] A functor for two Peano systems
borgauf at gmail.com
Mon Apr 5 17:12:38 UTC 2021
Not sure what you mean by "Why are you trying to write C code in Haskell?"
Please explain. This whole exercise is my attempt to translate *The
Littler MLer* and its last chapter where they go into functors. The authors
are old Scheme men. Maybe that's the problem?
On Mon, Apr 5, 2021 at 6:53 AM Anthony Clayden <anthony_clayden at clear.net.nz>
> > 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
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe