<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Is currying monadic?</title>
	<atom:link href="http://greenokapi.net/blog/2009/05/07/is-currying-monadic/feed/" rel="self" type="application/rss+xml" />
	<link>http://greenokapi.net/blog/2009/05/07/is-currying-monadic/</link>
	<description>Perl, Haskell, stuff</description>
	<pubDate>Thu, 11 Mar 2010 02:54:36 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Shin-Cheng Mu</title>
		<link>http://greenokapi.net/blog/2009/05/07/is-currying-monadic/#comment-1701</link>
		<dc:creator>Shin-Cheng Mu</dc:creator>
		<pubDate>Fri, 08 May 2009 07:45:20 +0000</pubDate>
		<guid isPermaLink="false">http://greenokapi.net/blog/?p=163#comment-1701</guid>
		<description>Ganesh is right that it looks like a state monad, where the state is perhaps a stack of arguments. Rather then "get first parameter" and "get second parameter", you will have one command getting the next parameter. 

However, you'd really want some static type checking preventing you from calling getNextParameter too many times, while allowing you to but elements of different types in the stack. 

You can perhaps index a state monad-like structure by the type of call stack it expects. For example, "ST (Int, (Double, (Char, ()))) Int" could be the encoding of a function Int -&#62; Double -&#62; Char -&#62; Int, and the getNextParameter method might have type:

getNextParameter :: (a -&#62; ST as b) -&#62; ST (a , as) b

But I am not sure whether it is still a monad, though...</description>
		<content:encoded><![CDATA[<p>Ganesh is right that it looks like a state monad, where the state is perhaps a stack of arguments. Rather then "get first parameter" and "get second parameter", you will have one command getting the next parameter. </p>

<p>However, you'd really want some static type checking preventing you from calling getNextParameter too many times, while allowing you to but elements of different types in the stack. </p>

<p>You can perhaps index a state monad-like structure by the type of call stack it expects. For example, "ST (Int, (Double, (Char, ()))) Int" could be the encoding of a function Int -&gt; Double -&gt; Char -&gt; Int, and the getNextParameter method might have type:</p>

<p>getNextParameter :: (a -&gt; ST as b) -&gt; ST (a , as) b</p>

<p>But I am not sure whether it is still a monad, though...</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zoheb Vacheri</title>
		<link>http://greenokapi.net/blog/2009/05/07/is-currying-monadic/#comment-1700</link>
		<dc:creator>Zoheb Vacheri</dc:creator>
		<pubDate>Fri, 08 May 2009 01:20:47 +0000</pubDate>
		<guid isPermaLink="false">http://greenokapi.net/blog/?p=163#comment-1700</guid>
		<description>I just found a post that created a "Trivial Monad", like the one I talked about above like MayBe in Dan Piponi's blog. I think what you have done is recreate the "Trivial Monad" in Perl.

http://blog.sigfpe.com/2007/04/trivial-monad.html</description>
		<content:encoded><![CDATA[<p>I just found a post that created a "Trivial Monad", like the one I talked about above like MayBe in Dan Piponi's blog. I think what you have done is recreate the "Trivial Monad" in Perl.</p>

<p><a href="http://blog.sigfpe.com/2007/04/trivial-monad.html" rel="nofollow">http://blog.sigfpe.com/2007/04/trivial-monad.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wren ng thornton</title>
		<link>http://greenokapi.net/blog/2009/05/07/is-currying-monadic/#comment-1699</link>
		<dc:creator>wren ng thornton</dc:creator>
		<pubDate>Fri, 08 May 2009 01:05:10 +0000</pubDate>
		<guid isPermaLink="false">http://greenokapi.net/blog/?p=163#comment-1699</guid>
		<description>Er, it looks like your blog ate the asterices in (a * b * c -&gt;) and rendered them as italics.

(Reply: yeah, looks like it does formatting, I thought I'd turned that off for comments, *sigh*.  I've edited, adding some spacing which seems to work around that).</description>
		<content:encoded><![CDATA[<p>Er, it looks like your blog ate the asterices in (a * b * c ->) and rendered them as italics.</p>

<p>(Reply: yeah, looks like it does formatting, I thought I'd turned that off for comments, <em>sigh</em>.  I've edited, adding some spacing which seems to work around that).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wren ng thornton</title>
		<link>http://greenokapi.net/blog/2009/05/07/is-currying-monadic/#comment-1698</link>
		<dc:creator>wren ng thornton</dc:creator>
		<pubDate>Fri, 08 May 2009 01:03:57 +0000</pubDate>
		<guid isPermaLink="false">http://greenokapi.net/blog/?p=163#comment-1698</guid>
		<description>First the family Reader monads:

    Reader a = (a -&gt;)

So a curried multi-parameter function can be considered as a composition of many Readers.

    Reader a . Reader b . Reader c == (a -&gt;) . (b -&gt;) . (c -&gt;)

A monad is a functor equipped with two natural transformations that follow certain laws. So this composition is actually a composition of functors. Another way of looking at it is that we're wrapping many functors around the same holes, so we can rewrite the composition as (a -&gt; b -&gt; c -&gt; -) using dash as our metasyntactic variable, as is common in category theory. Similarly we can think of ([-] . [-] . [-]) which can also be written as [[[-]]].

For the [[[-]]] example, one of the monad laws allows us to collapse multiple layers into a single layer so every [[[X]]] can be mapped to some [[X]] and every [[X]] can be mapped to some [X], both with certain properties of "preserving structure". Now, in the case of Reader we should consider what that means. Using join requires that all the layers are the same (e.g. (a-&gt;).(a-&gt;)), but the join of the Reader monad collapses that so everyone reads from the same a (it maps every (a-&gt;a-&gt; X) to some (a-&gt; X)), which isn't what we want for currying.

But there is a different way that we can "collapse" the composition of different Reader monads. Namely, we can find a mapping from (a-&gt;).(b-&gt;).(c-&gt;) to (a * b * c -&gt;) aka ((a,b,c) -&gt;). This general process is what uncurrying is about, and the dual is currying.

So, to answer your question, no currying does not form a monad--- at least not directly. However, the type constructor Reader is itself a functor as well, not just (Reader X) for all X. So if we look at (-&gt;) as a functor, then the composition (a-&gt;).(b-&gt;).(c-&gt;) is remarkably similar to the expression [a]++[b]++[c] which can be reduced to [a,b,c] in analogue with (a * b * c-&gt;). Note particularly the two different operators in flight for both examples.

The natural isomorphism between (a-&gt;).(b-&gt;) and (a * b-&gt;) is quite different from the natural transformation from F.F to F. For one, the former is an isomorphism so we can rewrite in either direction. Other details have to do with the fact that (-&gt;) forms a category (with id and (.)) and that it doesn't form a monoid (with the same) except in the restricted case of endomorphisms (X-&gt;X). 

For un/currying to be possible the category for (-&gt;) must be cartesian closed, meaning it has all products and exponentials as objects. Most of the common categories are CCC, but not all are.</description>
		<content:encoded><![CDATA[<p>First the family Reader monads:</p>

<pre><code>Reader a = (a -&gt;)
</code></pre>

<p>So a curried multi-parameter function can be considered as a composition of many Readers.</p>

<pre><code>Reader a . Reader b . Reader c == (a -&gt;) . (b -&gt;) . (c -&gt;)
</code></pre>

<p>A monad is a functor equipped with two natural transformations that follow certain laws. So this composition is actually a composition of functors. Another way of looking at it is that we're wrapping many functors around the same holes, so we can rewrite the composition as (a -> b -> c -> -) using dash as our metasyntactic variable, as is common in category theory. Similarly we can think of ([-] . [-] . [-]) which can also be written as [[[-]]].</p>

<p>For the [[[-]]] example, one of the monad laws allows us to collapse multiple layers into a single layer so every [[[X]]] can be mapped to some [[X]] and every [[X]] can be mapped to some [X], both with certain properties of "preserving structure". Now, in the case of Reader we should consider what that means. Using join requires that all the layers are the same (e.g. (a->).(a->)), but the join of the Reader monad collapses that so everyone reads from the same a (it maps every (a->a-> X) to some (a-> X)), which isn't what we want for currying.</p>

<p>But there is a different way that we can "collapse" the composition of different Reader monads. Namely, we can find a mapping from (a->).(b->).(c->) to (a * b * c ->) aka ((a,b,c) ->). This general process is what uncurrying is about, and the dual is currying.</p>

<p>So, to answer your question, no currying does not form a monad--- at least not directly. However, the type constructor Reader is itself a functor as well, not just (Reader X) for all X. So if we look at (->) as a functor, then the composition (a->).(b->).(c->) is remarkably similar to the expression [a]++[b]++[c] which can be reduced to [a,b,c] in analogue with (a * b * c->). Note particularly the two different operators in flight for both examples.</p>

<p>The natural isomorphism between (a->).(b->) and (a * b->) is quite different from the natural transformation from F.F to F. For one, the former is an isomorphism so we can rewrite in either direction. Other details have to do with the fact that (->) forms a category (with id and (.)) and that it doesn't form a monoid (with the same) except in the restricted case of endomorphisms (X->X). </p>

<p>For un/currying to be possible the category for (->) must be cartesian closed, meaning it has all products and exponentials as objects. Most of the common categories are CCC, but not all are.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zoheb Vacheri</title>
		<link>http://greenokapi.net/blog/2009/05/07/is-currying-monadic/#comment-1697</link>
		<dc:creator>Zoheb Vacheri</dc:creator>
		<pubDate>Fri, 08 May 2009 00:51:53 +0000</pubDate>
		<guid isPermaLink="false">http://greenokapi.net/blog/?p=163#comment-1697</guid>
		<description>Given that Maybe is a Monad and not just an Applicative Functor, it should be easy to see by analogy that currying/application should also satisfy the Monad laws.</description>
		<content:encoded><![CDATA[<p>Given that Maybe is a Monad and not just an Applicative Functor, it should be easy to see by analogy that currying/application should also satisfy the Monad laws.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zoheb Vacheri</title>
		<link>http://greenokapi.net/blog/2009/05/07/is-currying-monadic/#comment-1696</link>
		<dc:creator>Zoheb Vacheri</dc:creator>
		<pubDate>Fri, 08 May 2009 00:01:22 +0000</pubDate>
		<guid isPermaLink="false">http://greenokapi.net/blog/?p=163#comment-1696</guid>
		<description>The code in the previous comment got screwed up

Prelude Control.Applicative&#62; import Control.Applicative


Prelude Control.Applicative&#62; pure (+)  Just 3  Just 4


&lt;i&gt;Just 7&lt;/i&gt;</description>
		<content:encoded><![CDATA[<p>The code in the previous comment got screwed up</p>

<p>Prelude Control.Applicative&gt; import Control.Applicative</p>

<p>Prelude Control.Applicative&gt; pure (+)  Just 3  Just 4</p>

<p><i>Just 7</i></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zoheb Vacheri</title>
		<link>http://greenokapi.net/blog/2009/05/07/is-currying-monadic/#comment-1695</link>
		<dc:creator>Zoheb Vacheri</dc:creator>
		<pubDate>Fri, 08 May 2009 00:00:20 +0000</pubDate>
		<guid isPermaLink="false">http://greenokapi.net/blog/?p=163#comment-1695</guid>
		<description>Currying is Applicative. This will be obvious if you look at the Control.Applicative class. Monads are an instance of Applicative. So currying could also be Monadic if they observe the monad laws

Prelude Control.Applicative&#62; import Control.Applicative
Prelude Control.Applicative&#62; pure (+)  Just 3  Just 4
Just 7

I used the MayBe Monad but you could create your own type that just boxes a value and pure could be simply something like id.</description>
		<content:encoded><![CDATA[<p>Currying is Applicative. This will be obvious if you look at the Control.Applicative class. Monads are an instance of Applicative. So currying could also be Monadic if they observe the monad laws</p>

<p>Prelude Control.Applicative&gt; import Control.Applicative
Prelude Control.Applicative&gt; pure (+)  Just 3  Just 4
Just 7</p>

<p>I used the MayBe Monad but you could create your own type that just boxes a value and pure could be simply something like id.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ganesh Sittampalam</title>
		<link>http://greenokapi.net/blog/2009/05/07/is-currying-monadic/#comment-1691</link>
		<dc:creator>Ganesh Sittampalam</dc:creator>
		<pubDate>Thu, 07 May 2009 13:30:15 +0000</pubDate>
		<guid isPermaLink="false">http://greenokapi.net/blog/?p=163#comment-1691</guid>
		<description>This is basically a state monad where the state is a list of arguments that you then pop one element off at a time. In Haskell you'd have some issues with type safety (since all the elements of a list have to have the same type and you might well want differently typed arguments), and you'd probably have to use some kind of indexed monad to get full static type checking for it.</description>
		<content:encoded><![CDATA[<p>This is basically a state monad where the state is a list of arguments that you then pop one element off at a time. In Haskell you'd have some issues with type safety (since all the elements of a list have to have the same type and you might well want differently typed arguments), and you'd probably have to use some kind of indexed monad to get full static type checking for it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
