[Haskell-beginners] Capture the notion of invertible
Javran Cheng
javran.c at gmail.com
Thu Mar 20 06:18:12 UTC 2014
I've tried that lens lib out, and it is exactly what I want.
few examples in GHCi:
λ> let pretty x = mapM_ print x
λ> pretty mat
[1,0,0,0,2]
[0,3,0,4,0]
[0,0,5,0,0]
[0,6,0,7,0]
[8,0,0,0,9]
λ> let shiftL = filter (/= 0) >>> (++ repeat 0) >>> take 5
λ> over (iso transpose transpose) (map shiftL) mat
[[1,3,5,4,2],[8,6,0,7,9],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]
λ> pretty $ over (iso transpose transpose) (map shiftL) mat
[1,3,5,4,2]
[8,6,0,7,9]
[0,0,0,0,0]
[0,0,0,0,0]
[0,0,0,0,0]
λ> pretty $ over ((iso transpose transpose).(iso (map reverse) (map
reverse) )) (map shiftL) mat
[0,0,0,0,0]
[0,0,0,0,0]
[0,0,0,0,0]
[1,3,0,4,2]
[8,6,5,7,9]
Off topic:
In addition, as David Young commented in my codereview question:
"rempty and rappend form a Category instance. "
This comment makes perfect sense to me, because "monoid-like" reminds
me of Data.Monoid,
which does not totally capture what I know about monoid: monad is
"just a monoid in the category of endofunctors"
but Monad is not in any sense fit into a Monoid.
Here I find that when I talk about "monoid-like", I actually refer to Category,
and Monad is an instance of Category, which backs up my guess.
In a word, can I say that when talking about reducing data (Sum,
Product, etc.), I'm referring to Monoid,
and when I talking about monoid-like composition, I'm referring to Category?
Javran
> Date: Tue, 18 Mar 2014 02:48:21 +0700
> From: Kim-Ee Yeoh <ky3 at atamo.com>
> To: The Haskell-Beginners Mailing List - Discussion of primarily
> beginner-level topics related to Haskell <beginners at haskell.org>
> Subject: Re: [Haskell-beginners] Capture the notion of invertible
> functions
> Message-ID:
> <CAPY+ZdTyj81gcUaZJfHGeta8rbjxup8ReKHJ=iy7ePzKkQPomQ at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> > When you're talking about invertible functions, the idea you're probably
> reaching for is an isomorphism -- that is, we want the function to have
> certain nice properties on top of just being a map from a -> b with an
> inverse map from b -> a.
>
> The usual meaning of 'f is invertible' is that it is both left- and
> right-invertible, thus making it bijective: see first bullet in [1].
>
> Here you're alluding to f being merely left-invertible, something I don't
> see mentioned in OP.
>
> > You also want the function to be a bijection, which is captured in the
> notion of an isomorphism.
>
> I'm reminded of a reddit convo where the idea was tossed out that
> semigroups should always be promoted to monoids [2].
>
> I argued no. I also cited a case where a supposedly nicer monoid causes
> more problems for a ghc hacker than the true semigroup [3].
>
> Having structure is nice. And sometimes we just have to work with what's
> given to us.
>
> Category theory calls a /monomorphism/ something that's strictly weaker
> than left-invertible. An arrow that's (additionally) left-invertible
> corresponds to a /split mono/.
>
> Hence in order of _decreasing_ niceness: Iso, Split mono, Mono. As research
> uncovers more interesting phenomena, this sequence will continuing growing
> to the right.
>
> We can't always impose that niceness because that nukes whatever we're
> studying. So we gotta respect the situation. And given lemons, make
> lemonade.
>
>
> [1]
> http://en.wikipedia.org/wiki/Bijection,_injection_and_surjection#Bijection
>
> [2]
> http://www.reddit.com/r/haskell/comments/1ou06l/improving_applicative_donotation/ccvtqot?context=1
>
> [3]
> http://www.reddit.com/r/haskell/comments/1ou06l/improving_applicative_donotation/ccy4n2d
--
Javran (Fang) Cheng
More information about the Beginners
mailing list