Making sense of currying in the context of the Hask Category

Hi, I'm a Haskell newbie and I couldn't quite make sense of how currying maps to the the Hask Category. How would I map, for instance (+) to a Hask 'arrow'? If objects are types on Hask, then would a -> a -> a be the first object on this chain? In that case, for the first arrow, would I have as many arrows as there are possible partial applications on this type? In other words, would I have (+) 1, (+) 2, (+) 3 ... all those transitioning to the second object ( a -> a ) Or, do I have ONE arrow only, like (+) a ? In either case, what happens after 'm left with the object a -> a? What function (arrow) mutates it to the final value 'a'? That's the function resulting from the previous partial application of (+), but that fuction only exists at run time, after you apply the first one. I guess the question is, if you'd have to write a diagram for this, what would you write beside each object and beside each arrow?

I think you just have to remember that Haskell's currying is a side
effect (haha) of all functions only actually taking one argument.
I may be off base with this since I only just started looking at
category theory, but it made sense when I sketched it out:
http://i.imgur.com/QriQm.png
Let me know if I've made any silly mistakes as I'm still learning too :-)
On Fri, Sep 28, 2012 at 10:07 AM, Lino Rosa
Hi,
I'm a Haskell newbie and I couldn't quite make sense of how currying maps to the the Hask Category. How would I map, for instance (+) to a Hask 'arrow'?
If objects are types on Hask, then would a -> a -> a be the first object on this chain?
In that case, for the first arrow, would I have as many arrows as there are possible partial applications on this type? In other words, would I have (+) 1, (+) 2, (+) 3 ... all those transitioning to the second object ( a -> a ) Or, do I have ONE arrow only, like (+) a ?
In either case, what happens after 'm left with the object a -> a? What function (arrow) mutates it to the final value 'a'? That's the function resulting from the previous partial application of (+), but that fuction only exists at run time, after you apply the first one. I guess the question is, if you'd have to write a diagram for this, what would you write beside each object and beside each arrow?
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Thu, Sep 27, 2012 at 10:07:53PM -0400, Lino Rosa wrote:
Hi,
I'm a Haskell newbie and I couldn't quite make sense of how currying maps to the the Hask Category. How would I map, for instance (+) to a Hask 'arrow'?
Type class polymorphism complicates matters, so for the moment let's pretend (+) works only on Int. Then (+) is an arrow from the object Int to the object (Int -> Int). (+) :: Int -> (Int -> Int) Hask is special in its ability to have *objects* which themselves represent arrows, like (Int -> Int). In category theory terms, it is "cartesian closed".
If objects are types on Hask, then would a -> a -> a be the first object on this chain?
No, the first object is just Int (or 'a') and the second is (Int -> Int).
In that case, for the first arrow, would I have as many arrows as there are possible partial applications on this type? In other words, would I have (+) 1, (+) 2, (+) 3 ... all those transitioning to the second object ( a -> a ) Or, do I have ONE arrow only, like (+) a ?
(+) 1, (+) 2, (+) 3, etc. are all different arrows. They all go from the object Int to itself. -Brent

Hi Lino,
Brent gave an excellent answer. Looking up "cartesian closed category"
should yield even more insights.
On Fri, Sep 28, 2012 at 9:07 AM, Lino Rosa
That's the function resulting from the previous partial application of (+), but that fuction only exists at run time, after you apply the first one.
When you speak of a function that "only exists at run time", I think you're alluding to partial evaluation. Haskell doesn't do that, although many have wished for it. -- Kim-Ee

Thanks for the responses :) I've read on cartesian closed categories,
but I guess I need more time for it to sink in - my knowlege on
category theory is *very* limited.
Still, continuing on the Int + Int example. Would this be the sequence
of transformations, then?
Int -> (Int -> Int) -> Int
(+) (z) (?)
What do I label the arrow (?) ?
I understand the first transformation as "function (+) when applied to
an Int will result in (Int -> Int)". How would I describe function (?)
similarly ?
It's almost as it the arrow is z and (?) is the Int and I'm applying z
to (?), but that makes no sense!
If I understood correctly, 'z' would be a special type, one which when
applied (?) would return the final Int. This comes Hask being
cartesian closed. Still I'm clueless on the arrow (?)
On Fri, Sep 28, 2012 at 8:07 AM, Kim-Ee Yeoh
Hi Lino,
Brent gave an excellent answer. Looking up "cartesian closed category" should yield even more insights.
On Fri, Sep 28, 2012 at 9:07 AM, Lino Rosa
wrote: That's the function resulting from the previous partial application of (+), but that fuction only exists at run time, after you apply the first one.
When you speak of a function that "only exists at run time", I think you're alluding to partial evaluation. Haskell doesn't do that, although many have wished for it.
-- Kim-Ee

On Fri, Sep 28, 2012 at 08:53:11PM -0400, Lino Rosa wrote:
Thanks for the responses :) I've read on cartesian closed categories, but I guess I need more time for it to sink in - my knowlege on category theory is *very* limited.
Still, continuing on the Int + Int example. Would this be the sequence of transformations, then?
You seem quite set on this idea of there being "a sequence of transformations", I am not sure why. When thinking about (+) there are many different related arrows; some of them form sequences (can be composed) and some can't. So this is not necessarily a helpful way of thinking about things.
Int -> (Int -> Int) -> Int (+) (z) (?)
What do I label the arrow (?) ?
That said, you could label the arrow (?) with something like ($2) which means "apply a function to the argument 2".
I understand the first transformation as "function (+) when applied to an Int will result in (Int -> Int)". How would I describe function (?) similarly ? It's almost as it the arrow is z and (?) is the Int and I'm applying z to (?), but that makes no sense!
If I understood correctly, 'z' would be a special type, one which when applied (?) would return the final Int. This comes Hask being cartesian closed. Still I'm clueless on the arrow (?)
I think you actually had it right here. Indeed it does not make sense for (?) to be an Int, but it can indeed be a function like "apply the input to the argument 2". Having an "apply" operation is one of the criteria for being cartesian closed. -Brent
On Fri, Sep 28, 2012 at 8:07 AM, Kim-Ee Yeoh
wrote: Hi Lino,
Brent gave an excellent answer. Looking up "cartesian closed category" should yield even more insights.
On Fri, Sep 28, 2012 at 9:07 AM, Lino Rosa
wrote: That's the function resulting from the previous partial application of (+), but that fuction only exists at run time, after you apply the first one.
When you speak of a function that "only exists at run time", I think you're alluding to partial evaluation. Haskell doesn't do that, although many have wished for it.
-- Kim-Ee
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Thu, 27 Sep 2012, Lino Rosa
Hi,
I'm a Haskell newbie and I couldn't quite make sense of how currying maps to the the Hask Category. How would I map, for instance (+) to a Hask 'arrow'?
There are several categories that might be called "the Hask category". At http://www.haskell.org/haskellwiki/Hask there are pointers to papers on what a useful Hask might be. Let us consider the category SET whose objects are sets and whose morphisms are everywhere defined single valued maps. So a morphism f: X -> B, where X and B are sets, would just be a function, usual modern sense, from X to B. Now the set of all morphisms from X to B, let us call it SET(X;B), is itself a set, so SET(X;B) is an object of SET. Now suppose B is the set SET(Y;Z) of morphisms from the set X to the set Y. In this case given an element x of X, we have that f(x) is a morphism of SET, and f(x) has source Y and target Z, that is, f(x): Y -> Z. So given x, and now given y in Y, we have a new two place function, call it g: X x Y -> Z, defined by: for all x in X and y in Y, g(x, y) = [f(x)](y) where the square brackets are just for grouping. Note that we have the "operation" of Cartesian product on objects of SET, which operation is shown above as the "x" in the expression "X x Y". Note also that SET is an odd sort of category in that SET(X;B), for any two objects X, B, is itself an object of SET. Now in SET we may also, for any g: X x Y -> Z get an f: X -> SET(Y;Z), such that our condition holds. Category theorists apparatus to make explicit what we have just claimed in vague and not quite precise terms. This apparatus is the theory of Cartesian Closed Categories: http://en.wikipedia.org/wiki/Cartesian_closed_category [page was last modified on 28 September 2012 at 19:08] Let me give an example of our imprecision, which formal category theory clarifies: We said that g is a two place function. We also wrote g: X x Y -> Z. What does this mean? In any category every morphism goes from exactly one object to exactly one object. So how can there be such a thing as a "function with two inputs"? oo--JS.
If objects are types on Hask, then would a -> a -> a be the first object on this chain?
In that case, for the first arrow, would I have as many arrows as there are possible partial applications on this type? In other words, would I have (+) 1, (+) 2, (+) 3 ... all those transitioning to the second object ( a -> a ) Or, do I have ONE arrow only, like (+) a ?
In either case, what happens after 'm left with the object a -> a? What function (arrow) mutates it to the final value 'a'? That's the function resulting from the previous partial application of (+), but that fuction only exists at run time, after you apply the first one. I guess the question is, if you'd have to write a diagram for this, what would you write beside each object and beside each arrow?
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Fri, 28 Sep 2012, Jay Sulzberger wrote:
On Thu, 27 Sep 2012, Lino Rosa
wrote: Hi,
I'm a Haskell newbie and I couldn't quite make sense of how currying maps to the the Hask Category. How would I map, for instance (+) to a Hask 'arrow'?
There are several categories that might be called "the Hask category". At
http://www.haskell.org/haskellwiki/Hask
there are pointers to papers on what a useful Hask might be.
Let us consider the category SET whose objects are sets and whose morphisms are everywhere defined single valued maps. So a morphism f: X -> B, where X and B are sets, would just be a function, usual modern sense, from X to B. Now the set of all morphisms from X to B, let us call it SET(X;B), is itself a set, so SET(X;B) is an object of SET.
Now suppose B is the set SET(Y;Z) of morphisms from the set X to the set Y. In this case given an element x of X, we have that
Oi, typo: Above lines should be: Now suppose B is the set SET(Y;Z) of morphisms from the set Y to the set Z. In this case given an element x of X, we have that
f(x) is a morphism of SET, and f(x) has source Y and target Z, that is, f(x): Y -> Z. So given x, and now given y in Y, we have a new two place function, call it g: X x Y -> Z, defined by:
for all x in X and y in Y, g(x, y) = [f(x)](y)
where the square brackets are just for grouping.
Note that we have the "operation" of Cartesian product on objects of SET, which operation is shown above as the "x" in the expression "X x Y". Note also that SET is an odd sort of category in that SET(X;B), for any two objects X, B, is itself an object of SET.
Now in SET we may also, for any g: X x Y -> Z get an f: X -> SET(Y;Z), such that our condition holds.
Category theorists apparatus to make explicit what we have just
and another, above line should be Category theorists have apparatus to make explicit what we have just oo--JS.
claimed in vague and not quite precise terms. This apparatus is the theory of Cartesian Closed Categories:
http://en.wikipedia.org/wiki/Cartesian_closed_category [page was last modified on 28 September 2012 at 19:08]
Let me give an example of our imprecision, which formal category theory clarifies:
We said that g is a two place function. We also wrote g: X x Y -> Z. What does this mean? In any category every morphism goes from exactly one object to exactly one object. So how can there be such a thing as a "function with two inputs"?
oo--JS.
If objects are types on Hask, then would a -> a -> a be the first object on this chain?
In that case, for the first arrow, would I have as many arrows as there are possible partial applications on this type? In other words, would I have (+) 1, (+) 2, (+) 3 ... all those transitioning to the second object ( a -> a ) Or, do I have ONE arrow only, like (+) a ?
In either case, what happens after 'm left with the object a -> a? What function (arrow) mutates it to the final value 'a'? That's the function resulting from the previous partial application of (+), but that fuction only exists at run time, after you apply the first one. I guess the question is, if you'd have to write a diagram for this, what would you write beside each object and beside each arrow?
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (5)
-
Brent Yorgey
-
Jay Sulzberger
-
Kim-Ee Yeoh
-
Lino Rosa
-
Lyndon Maydwell