Re: [Haskell-cafe] A functor for two Peano systems

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

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
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.

I think the confusion here is that the word "functor" in ML means something
very different than the word "functor" in Haskell. The concept of an
ML-style functor exists in modern GHC as Backpack <
https://gitlab.haskell.org/ghc/ghc/-/wikis/backpack> but it's not very
commonly used (yet?) and it would probably be counterproductive to try and
learn how to use that while also learning the basics of Haskell.
Typeclasses are often used in Haskell in places where you'd use a Functor
in ML, but they are not quite the same thing.
On Mon, Apr 5, 2021 at 10:13 AM Galaxy Being
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@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.
_______________________________________________ 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.
participants (3)
-
Anthony Clayden
-
Bob Ippolito
-
Galaxy Being