A functor for two Peano systems

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

I think your last guess is correct... what you're trying to build appears
to be a semigroup (or monoid), not a functor.
On Sun, Apr 4, 2021, 10:18 PM Galaxy Being
I'm just not understanding the concept of a functor in this context: I have this
plus :: Int -> Int -> Int plus n m = if (n == 0) then m else sCessor (plus (pCessor n) m) where sCessor x = x + 1 pCessor x = if (x == 0) then error "too small" else (x - 1)
and this
data MyNum = MNZero | OneMoreThan MyNum deriving (Show,Eq,Ord)
plus2 :: MyNum -> MyNum -> MyNum plus2 n m = if (n == MNZero) then m else sCessor (plus2 (pCessor n) m) where sCessor x = (OneMoreThan x) pCessor x = if (x == MNZero) then (error "too small") else (oneLess x) oneLess MNZero = MNZero oneLess (OneMoreThan myn) = myn
It seems there should be just one plus, function that would handle both an Int-based Peano and the MyNum-based Peano, not two. But in this definition
fmap :: (a -> b) -> f a -> f b
The (a -> b) should be "lifted" over the f a -> f b 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 plus :: Int -> Int -> Int and the plus2 :: MyNum -> MyNum -> MyNum. Trying to get started, I would assume I need some sort of instance Functor MyNum describing, yeah, what? Or am I barking up the completely wrong tree here, i.e., this isn't a functor issue?
LB
_______________________________________________ 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.

On Mon, Apr 05, 2021 at 12:17:23AM -0500, Galaxy Being wrote:
I'm just not understanding the concept of a functor in this context: I have this [...] It seems there should be just one plus, function that would handle both an Int-based Peano and the MyNum-based Peano, not two. But in this definition
fmap :: (a -> b) -> f a -> f b
The (a -> b) should be "lifted" over the f a -> f b But I can't conceive of how this should all fit together
Are you perhaps confusing the ML notion of "functor" with the Haskell notion of "Functor" (which is just a particular typeclass)? In fact, Haskell's type classes as a whole are probably closer to ML's "functors" than Haskell's "Functor"s are! Tom

That must be my problem. Thanks for the info. On Mon, Apr 5, 2021 at 12:36 PM Tom Ellis < tom-lists-haskell-cafe-2017@jaguarpaw.co.uk> wrote:
On Mon, Apr 05, 2021 at 12:17:23AM -0500, Galaxy Being wrote:
I'm just not understanding the concept of a functor in this context: I have this [...] It seems there should be just one plus, function that would handle both an Int-based Peano and the MyNum-based Peano, not two. But in this definition
fmap :: (a -> b) -> f a -> f b
The (a -> b) should be "lifted" over the f a -> f b But I can't conceive of how this should all fit together
Are you perhaps confusing the ML notion of "functor" with the Haskell notion of "Functor" (which is just a particular typeclass)?
In fact, Haskell's type classes as a whole are probably closer to ML's "functors" than Haskell's "Functor"s are!
Tom _______________________________________________ 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)
-
Akhra Gannon
-
Galaxy Being
-
Tom Ellis