[Haskell-cafe] A functor for two Peano systems

Galaxy Being 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>
wrote:

> > 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?)
>
>
> AntC
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210405/3edc5dd8/attachment.html>


More information about the Haskell-Cafe mailing list