[Haskell-cafe] A functor for two Peano systems
Akhra Gannon
tanuki at gmail.com
Mon Apr 5 05:58:15 UTC 2021
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 <borgauf at gmail.com> wrote:
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210404/a97bd0da/attachment.html>
More information about the Haskell-Cafe
mailing list