<div dir="ltr">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 <<a href="https://gitlab.haskell.org/ghc/ghc/-/wikis/backpack">https://gitlab.haskell.org/ghc/ghc/-/wikis/backpack</a>> 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.<div><br></div><div>Typeclasses are often used in Haskell in places where you'd use a Functor in ML, but they are not quite the same thing.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 5, 2021 at 10:13 AM Galaxy Being <<a href="mailto:borgauf@gmail.com">borgauf@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">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 <i>The Littler MLer</i> and its last chapter where they go into functors. The authors are old Scheme men. Maybe that's the problem?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 5, 2021 at 6:53 AM Anthony Clayden <<a href="mailto:anthony_clayden@clear.net.nz" target="_blank">anthony_clayden@clear.net.nz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><font face="monospace">> <span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">Or am I barking up the </span><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">completely wrong tree here, i.e., this isn't a functor issue?</span></font><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">Yes you are barking up the wrong tree/no this isn't a Functor issue.</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><font face="monospace"><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">> </span><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">create just one generic plus </span><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">that would handle both the plus :: Int -> Int -> Int and the plus2 :: MyNum </span><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap">-> MyNum -> MyNum.</span></font></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">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.</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">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:</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">> class PolyPlus a where polyPlus :: a -> a -> a</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">> instance PolyPlus Int where polyPlus = plus</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">> instance PolyPlus MyNum where polyPlus = plus2</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">(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?)</font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace"><br></font></span></div><div><span style="color:rgb(0,0,0);font-size:1em;white-space:pre-wrap"><font face="monospace">AntC</font></span></div><div><br></div></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>