[Haskell-beginners] Constrained polymorphic functions as natural transformations
Matt R
habari.zerglings at gmail.com
Sun Jan 5 20:01:56 UTC 2014
On 22 December 2013 20:26, Brent Yorgey <byorgey at seas.upenn.edu> wrote:
> You have encoded a Foo dictionary as an Either Int a -> Either a Int
> function, but that is very different than saying that having a Foo
> dictionary is *equivalent* to having an Either Int a -> Either a Int
> function. They are not equivalent; in particular, you could have a
> function which sends Left 5 to Right 6, which does not correpond to
> anything in Foo. Put another way, if you try to write a Foo instance
> given only some unknown function of type (Either Int a -> Either a
> Int), you will find that you cannot do it. So my point stands that it
> is not always possible to *characterize* a type class as a natural
> transformation.
OK, I think see what you're saying: while you can represent any Foo
instance as an "Either Int a -> Either a Int", not every "Either Int a ->
Either a Int" represents a Foo instance.
I guess I was originally hoping to encode a bunch of equations into a
single one, so that rather than a collection of similar equations, one for
each function in the type class...
fmap f . foo == foo . fmap f
fmap f . bar == bar . fmap f
fmap f . baz == baz . fmap f
...you could encode the typeclass signature as some function "sig" and
express the same condition as a single equation (which would be true if and
only if the above equations were true):
fmap f . sig == sig . fmap f
I don't know if that's always possible. As you pointed out, you'd need
dinatural transformations in general, which I've had a look at, although I
confess I find it hard to get the same intuition about them as for regular
natural transformations. If you wanted to write that blog post, you'd have
at least one guaranteed keen reader ;-)
Cheers,
-- Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140105/4a3e0e63/attachment.html>
More information about the Beginners
mailing list