<div dir="ltr">I'm just not understanding the concept of a functor in this context: I have this <div><br></div><div><font face="monospace">plus :: Int -> Int -> Int<br>plus n m = if (n == 0)<br>           then m<br>           else sCessor (plus (pCessor n) m)<br>                where sCessor x = x + 1<br>                      pCessor x = if (x == 0)<br>                                  then error "too small"<br>                                  else (x - 1)</font><br></div><div><br></div><div>and this</div><div><br></div><div><font face="monospace">data MyNum = MNZero | OneMoreThan MyNum deriving (Show,Eq,Ord)<br></font></div><div><font face="monospace"><br></font></div><div><font face="monospace">plus2 :: MyNum -> MyNum -> MyNum<br>plus2 n m = if (n == MNZero)<br>            then m<br>            else sCessor (plus2 (pCessor n) m)<br>                 where sCessor x = (OneMoreThan x)<br>                       pCessor x = if (x == MNZero)<br>                                   then (error "too small")<br>                                   else (oneLess x)<br>                       oneLess MNZero = MNZero<br>                       oneLess (OneMoreThan myn) = myn</font><br></div><div><br></div><div>It seems there should be just one <font face="monospace">plus</font>, function that would handle both an <font face="monospace">Int</font>-based Peano and the <font face="monospace">MyNum</font>-based Peano, not two. But in this definition</div><div><br></div><div><font face="monospace">fmap :: (a -> b) -> f a -> f b</font><br></div><div><br></div><div>The <font face="monospace">(a -> b) </font>should be "lifted" over the <font face="monospace">f a -> f b </font><font face="arial, sans-serif">But I can't conceive of how this should all fit together, i.e., to create just one generic plus that would handle both the </font><font face="monospace">plus :: Int -> Int -> Int</font> and the <font face="monospace">plus2 :: MyNum -> MyNum -> MyNum</font>. Trying to get started, I would assume I need some sort of instance <font face="monospace">Functor MyNum</font> describing, yeah, what? Or am I barking up the completely wrong tree here, i.e., this isn't a functor issue?</div><div><br></div><div>LB</div><div><br></div></div>