[Haskell-beginners] Constrained polymorphic functions as natural transformations

Matt R habari.zerglings at gmail.com
Fri Dec 13 15:25:03 UTC 2013


Hi Brent,

Many thanks for taking the time to have a look! Hope you might be able to
cope with some more amateurish fumbling as I try and expand my
understanding...

On 14 November 2013 13:59, Brent Yorgey <byorgey at seas.upenn.edu> wrote:


> In general one must consider what are called
> *di*natural transformations.  (I ought to write a blog post about
> this.)...but I thought I would mention it in case you want to look it up
> later.


Thanks -- dinatural transformations are probably a bit beyond my comfort
zone right now, but I'll add it to my list of things to look at.

Interesting to discover that not all polymorphic functions are natural
transformations. "fix" seems rather exotic -- are there any less unusual
examples?

Note that you can't always characterize a type class by a single
> function like this.  For example, consider class Foo ... There is no way
> to pick functors f and g such that a Foo dictionary is
> equivalent to  f a -> g a.
>

I was wondering why the following wouldn't do the trick?

sig :: Foo a => Either Int a -> Either a Int
sig (Left n) = Left (bar n)
sig (Right a) = Right (baz a)


> This doesn't really make sense.  If a natural transformation
> consists of a family of arrows which all live in Hask_T,


In this case, I think the family of arrows lives in Hask -- we can
reinterpret our Hask endofunctors as instead being functors from Hask_T ->
Hask. Then there's no requirement on our constrained polymorphic functions
to commute with sig.

In your example function f, the two functors would be the identify functor
"Id" and a constant functor "K Foo", and naturality is just saying that,
for any function g: A -> B that satisfies show == show . f, then:

f = f . g

Which is clearly true for f.


Am I still barking up the wrong tree? Apologies if so, but it *feels* like
there should be something here, with the intuition that:

Functions that don't "inspect" their values ==> you can substitute values
without fundamentally affecting the action of the function ==> natural
transformations between Hask endofunctors.

Functions that don't inspect their values other than through a particular
interface T ==> you can substitute values without fundamentally affecting
the action of the function, providing your substitution is invisible
through the interface T ==> Natural transformations between functors Hask_T
-> Hask.

-- Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131213/14a92d18/attachment.html>


More information about the Beginners mailing list