<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>porges &#187; criticism</title>
	<atom:link href="http://porg.es/blog/tag/criticism/feed" rel="self" type="application/rss+xml" />
	<link>http://porg.es/blog</link>
	<description>... master of none</description>
	<lastBuildDate>Sat, 12 Sep 2009 07:57:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Making Maya&#8217;s Python palatable</title>
		<link>http://porg.es/blog/making-mayas-python-palatable</link>
		<comments>http://porg.es/blog/making-mayas-python-palatable#comments</comments>
		<pubDate>Tue, 03 Mar 2009 04:57:12 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[criticism]]></category>
		<category><![CDATA[maya]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[short]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=300</guid>
		<description><![CDATA[Maya&#8217;s python interface leaves something to be desired, as it seems like a straight port of their existing MEL interface with no additional thought put into designing a nice OO interface. For example, here is how to set or get the ‘radius’ attribute of a sphere: s = cmds.sphere&#40;&#41; r = cmds.sphere&#40;s, query=True, radius=True&#41; cmds.sphere&#40;s, [...]]]></description>
			<content:encoded><![CDATA[<p>Maya&#8217;s python interface leaves something to be desired, as it seems like a straight port of their existing MEL interface with no additional thought put into designing a nice OO interface. For example, here is how to set or get the ‘<code>radius</code>’ attribute of a sphere:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">s = cmds.<span style="color: black;">sphere</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
r = cmds.<span style="color: black;">sphere</span><span style="color: black;">&#40;</span>s, query=<span style="color: #008000;">True</span>, radius=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
cmds.<span style="color: black;">sphere</span><span style="color: black;">&#40;</span>s, edit=<span style="color: #008000;">True</span>, radius=<span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Nasty.</p>
<p>So, here is a wrapper to make things nicer:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> maya.<span style="color: black;">cmds</span> <span style="color: #ff7700;font-weight:bold;">as</span> cmds
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Wrapper<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, other<span style="color: black;">&#41;</span>:
		<span style="color: #008000;">self</span>.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'me'</span><span style="color: black;">&#93;</span> = other<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__getattr__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, thing<span style="color: black;">&#41;</span>:
		i = <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">if</span> cmds.<span style="color: black;">attributeQuery</span><span style="color: black;">&#40;</span>thing, node=<span style="color: #008000;">self</span>.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'me'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, exists=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: #ff4500;">1</span>
		<span style="color: #ff7700;font-weight:bold;">return</span> cmds.<span style="color: black;">getAttr</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'me'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot;.&quot;</span> + thing<span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__setattr__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, thing, value<span style="color: black;">&#41;</span>:
		i = <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">if</span> cmds.<span style="color: black;">attributeQuery</span><span style="color: black;">&#40;</span>thing, node=<span style="color: #008000;">self</span>.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'me'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, exists=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: #ff4500;">1</span>
		cmds.<span style="color: black;">setAttr</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: #0000cd;">__dict__</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'me'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot;.&quot;</span> + name, value<span style="color: black;">&#41;</span></pre></div></div>

<p>The above example is now:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">s = Wrapper<span style="color: black;">&#40;</span>cmds.<span style="color: black;">sphere</span><span style="color: black;">&#41;</span>
r = s.<span style="color: black;">radius</span>
s.<span style="color: black;">radius</span> = <span style="color: #ff4500;">10</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/making-mayas-python-palatable/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Annoyances with Intrepid</title>
		<link>http://porg.es/blog/annoyances-with-intrepid</link>
		<comments>http://porg.es/blog/annoyances-with-intrepid#comments</comments>
		<pubDate>Thu, 26 Feb 2009 22:30:16 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[commentary]]></category>
		<category><![CDATA[annoyance]]></category>
		<category><![CDATA[ati]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[compiz]]></category>
		<category><![CDATA[criticism]]></category>
		<category><![CDATA[dvd]]></category>
		<category><![CDATA[intrepid]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=297</guid>
		<description><![CDATA[After having just installed Intrepid on a friend’s PC last night: I ran into this bug (here’s the fix) ATi’s dual monitor setup is still too hard (here’s how to do it) ATi’s drivers can’t do compiz and video at the same time (Install the latest drivers to fix it)]]></description>
			<content:encoded><![CDATA[<p>After having just installed Intrepid on a friend’s PC last night:</p>
<ul>
<li>I ran into <a href="https://bugs.launchpad.net/ubuntu/+source/mplayer/+bug/197068">this bug</a> (<a href="http://ubuntuforums.org/showpost.php?p=5014367&#038;postcount=4">here’s the fix</a>)</li>
<li>ATi’s dual monitor setup is still too hard (<a href="http://ubuntuforums.org/showpost.php?p=4486852&#038;postcount=6">here’s how to do it</a>)</li>
<li>ATi’s drivers can’t do compiz and video at the same time (<a href="http://wiki.cchtml.com/index.php/Ubuntu_Intrepid_Installation_Guide#Installing_the_restricted_drivers_manually">Install the latest drivers to fix it</a>)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/annoyances-with-intrepid/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parametrizing Monoids and Monads</title>
		<link>http://porg.es/blog/parametrizing-monoids-and-monads</link>
		<comments>http://porg.es/blog/parametrizing-monoids-and-monads#comments</comments>
		<pubDate>Mon, 16 Feb 2009 05:10:19 +0000</pubDate>
		<dc:creator>Porges</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[arity]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[criticism]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[indexed]]></category>
		<category><![CDATA[monad]]></category>
		<category><![CDATA[monads]]></category>

		<guid isPermaLink="false">http://porg.es/blog/?p=284</guid>
		<description><![CDATA[Dan Piponi’s latest post “Beyond Monads” has prompted some wonderment (and forehead-slapping). For example: How did we all miss that before? —Peaker The answer (of course!) is that while we might have, they didn&#8217;t. For example, Edward Kmett’s category-extras package has had Control.Monad.Indexed available for use in Haskell since early last year, while the concept [...]]]></description>
			<content:encoded><![CDATA[<p>Dan Piponi’s latest post “<a href="http://blog.sigfpe.com/2009/02/beyond-monads.html">Beyond Monads</a>” has prompted some wonderment (and forehead-slapping). For example:</p>
<blockquote><p>How did we all miss that before?<img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
<p style="text-align:right">—<cite><a href="http://www.reddit.com/r/haskell/comments/7xi0r/a_neighborhood_of_infinity_beyond_monads/c07ohx9">Peaker</a></cite></p></blockquote>
<p>The answer (of course!) is that while <em>we</em> might have, <em>they</em> didn&#8217;t. <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /> For example, Edward Kmett’s <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/category-extras-0.53.5">category-extras</a> package has had <a href="http://hackage.haskell.org/packages/archive/category-extras/0.53.5/doc/html/Control-Monad-Indexed.html">Control.Monad.Indexed</a> available for use in Haskell since early last year, while the concept for its implementation in Haskell has been around since at least 2005 (see the paper “<a href="http://crab.rutgers.edu/~pjohann/f14-ghani.pdf">Monadic Augment and Generalised Short Cut Fusion</a>”). Needless to say, Oleg has <a href="http://okmij.org/ftp/Computation/monads.html#param-monad">been there</a> too.</p>
<p>For me, this prompted a vaguely-related revelation. Say that we have a Category class:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">class</span> Category <span style="color: green;">&#40;</span>⤳<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span>
	<span style="font-weight: bold;">id</span> ∷ a ⤳ a
	<span style="color: green;">&#40;</span>∘<span style="color: green;">&#41;</span> ∷ <span style="color: green;">&#40;</span>b ⤳ c<span style="color: green;">&#41;</span> → <span style="color: green;">&#40;</span>a ⤳ b<span style="color: green;">&#41;</span> → <span style="color: green;">&#40;</span>a ⤳ c<span style="color: green;">&#41;</span></pre></div></div>

<p>I had recently been wondering how categories other than (→), such as graphs (and even the trivial category) fit into this model. Now that I have figured it out, the answer is simple; it is a matter of arity. Graphs and other datastructure-related categories don’t have the extra type arguments (unless you’re working in a dependently-typed language), and so can’t fit into this. What we want to do is <em>fake</em> the extra arguments, by having some extra ones that we can just ignore (the name, FF, is short for FakeFake, i.e. two fake arguments).</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">newtype</span> FF f a b <span style="color: #339933; font-weight: bold;">=</span> FF <span style="color: green;">&#123;</span> unFF <span style="color: #339933; font-weight: bold;">::</span> f <span style="color: green;">&#125;</span></pre></div></div>

<p>Now we can define the trivial category!</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">class</span> Category <span style="color: green;">&#40;</span>FF <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span>
	<span style="font-weight: bold;">id</span> <span style="color: #339933; font-weight: bold;">=</span> FF <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
	f ∘ g <span style="color: #339933; font-weight: bold;">=</span> FF <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span></pre></div></div>

<p>Viewed in this light, it is obvious why (as Dan notes in the original post) Monoids give rise to Monads and Categories give rise to ParametrizedMonads, as we have:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">class</span> Monoid m ⇒ Category <span style="color: green;">&#40;</span>FF m<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span>
	<span style="font-weight: bold;">id</span> <span style="color: #339933; font-weight: bold;">=</span> FF mempty
	<span style="color: green;">&#40;</span>FF f<span style="color: green;">&#41;</span> ∘ <span style="color: green;">&#40;</span>FF g<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> FF <span style="color: green;">&#40;</span>mappend f g<span style="color: green;">&#41;</span></pre></div></div>

<p>Next, we want to write implementations for all our old Monads in the new PMonad class. We might do it like this (with a new newtype for the different arguments of this datatype, RealFakeFakeReal):</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">newtype</span> RFFR f x y a <span style="color: #339933; font-weight: bold;">=</span> RFFR <span style="color: green;">&#123;</span> unRFFR ∷ <span style="color: green;">&#40;</span>f a<span style="color: green;">&#41;</span> <span style="color: green;">&#125;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">class</span> PMonad m <span style="color: #06c; font-weight: bold;">where</span>
	<span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&gt;&gt;=</span><span style="color: green;">&#41;</span> ∷ m s1 s2 a → <span style="color: green;">&#40;</span>a → m s2 s3 b<span style="color: green;">&#41;</span> → m s1 s3 b
	<span style="font-weight: bold;">return</span> ∷ a → m s s a
&nbsp;
<span style="color: #06c; font-weight: bold;">instance</span> <span style="color: green;">&#40;</span>Old<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Monad</span> m<span style="color: green;">&#41;</span> ⇒ PMonad <span style="color: green;">&#40;</span>RFFR m<span style="color: green;">&#41;</span> <span style="color: #06c; font-weight: bold;">where</span>
	<span style="color: green;">&#40;</span>RFFR x<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> f <span style="color: #339933; font-weight: bold;">=</span> RFFR <span style="color: green;">&#40;</span>x Old<span style="color: #339933; font-weight: bold;">.&gt;&gt;=</span> unRFFR ∘ f<span style="color: green;">&#41;</span>
	<span style="font-weight: bold;">return</span> x <span style="color: #339933; font-weight: bold;">=</span> RFFR <span style="color: green;">&#40;</span>Old<span style="color: #339933; font-weight: bold;">.</span><span style="font-weight: bold;">return</span> x<span style="color: green;">&#41;</span></pre></div></div>

<p>There is a big issue that this highlights. It is <em>hard</em> to work with types of different arities in Haskell. (This is noted in the ‘<a href="http://haskell.org/haskellwiki/Quantified_contexts">quantified contexts</a>’ proposal.)</p>
<p>As an example, since we now know that every Monoid is a Category, we might think to drop Monoids and just use Categories everywhere (I should note that this is actually a silly idea <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_razz.gif" alt="" />!). Unfortunately, we can’t just do this as we’ll have to use <code>FF</code> wrappers/unwrappers everywhere:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">x <span style="color: #339933; font-weight: bold;">=</span> unFF <span style="color: #339933; font-weight: bold;">$</span> FF <span style="color: green;">&#91;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">3</span><span style="color: green;">&#93;</span> ∘ FF <span style="color: green;">&#91;</span><span style="color: red;">4</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">5</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">6</span><span style="color: green;">&#93;</span></pre></div></div>

<p>I have not yet found a workaround for this. Help would be nice <img src="http://porg.es/blog/wp-content/plugins/wp-smiley-switcher/noktahhitam/icon_smile.gif" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://porg.es/blog/parametrizing-monoids-and-monads/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
