<?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: Monad exercises in Scala</title>
	<atom:link href="http://blog.tmorris.net/monad-exercises-in-scala/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tmorris.net/monad-exercises-in-scala/</link>
	<description>The weblog of Tony Morris</description>
	<pubDate>Sat, 19 May 2012 02:57:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: James</title>
		<link>http://blog.tmorris.net/monad-exercises-in-scala/#comment-150657</link>
		<dc:creator>James</dc:creator>
		<pubDate>Sat, 07 Jan 2012 05:03:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=716#comment-150657</guid>
		<description>Tardily concurring with Dominic — nice set of exercises, but it may’ve been a touch too frustrating figuring out how to interpret flatMap for InterMonad. It wasn’t clear to me that the integer argument to the “wrapped” function should be repeated ... although in retrospect I suppose it seems obvious.</description>
		<content:encoded><![CDATA[<p>Tardily concurring with Dominic — nice set of exercises, but it may’ve been a touch too frustrating figuring out how to interpret flatMap for InterMonad. It wasn’t clear to me that the integer argument to the “wrapped” function should be repeated &#8230; although in retrospect I suppose it seems obvious.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dominic Bou-Samra</title>
		<link>http://blog.tmorris.net/monad-exercises-in-scala/#comment-144082</link>
		<dc:creator>Dominic Bou-Samra</dc:creator>
		<pubDate>Sat, 17 Dec 2011 23:58:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=716#comment-144082</guid>
		<description>This was such a useful exercise for someone super fresh to FP and Scala. I struggled with the InterMonad though.</description>
		<content:encoded><![CDATA[<p>This was such a useful exercise for someone super fresh to FP and Scala. I struggled with the InterMonad though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marius</title>
		<link>http://blog.tmorris.net/monad-exercises-in-scala/#comment-42505</link>
		<dc:creator>Marius</dc:creator>
		<pubDate>Wed, 30 Jun 2010 14:29:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=716#comment-42505</guid>
		<description>Dear Tony,

Thank you very much for your reply! ... however my puzzling thing (regardless of representation) is not really about category theory or Haskell representation but rather that  M[_] is not necessarily a functor or a monad for that matter. It is just a higher kinded type thus when we compose things we're not back in the monad's space that allows us to do further composition unless we wrap it int a Monad either explicitly or using implicit conversions.

In my second example all transformations return an M[T] which must be an Monad M trait refinement thus being easy to see further composition.

Appreciate your thoughts.

Br's,
Marius</description>
		<content:encoded><![CDATA[<p>Dear Tony,</p>
<p>Thank you very much for your reply! &#8230; however my puzzling thing (regardless of representation) is not really about category theory or Haskell representation but rather that  M[_] is not necessarily a functor or a monad for that matter. It is just a higher kinded type thus when we compose things we&#8217;re not back in the monad&#8217;s space that allows us to do further composition unless we wrap it int a Monad either explicitly or using implicit conversions.</p>
<p>In my second example all transformations return an M[T] which must be an Monad M trait refinement thus being easy to see further composition.</p>
<p>Appreciate your thoughts.</p>
<p>Br&#8217;s,<br />
Marius</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/monad-exercises-in-scala/#comment-42087</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Sun, 20 Jun 2010 05:27:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=716#comment-42087</guid>
		<description>Hi Marius,
You are right that a Monad can also be represented as:

&lt;pre lang="Scala"&gt;
trait Monad[M[_]] extends Functor[M] {
  def unit[A](a: A): M[A]
  def mult(m: M[M[A]]): M[A]
}
&lt;/pre&gt;

This would allow you derive &lt;code&gt;flatMap&lt;/code&gt; as you have written.

Alternatively, &lt;code&gt;mult&lt;/code&gt; can be derived: &lt;code&gt;m =&gt; m.flatMap(x =&gt; x)&lt;/code&gt;. I have no particular preference for either representation, though I suspect there are ultimately practical implications. I'd be interested in knowing if this intuition is correct.</description>
		<content:encoded><![CDATA[<p>Hi Marius,<br />
You are right that a Monad can also be represented as:</p>

<div class="wp_syntax"><div class="code"><pre class="scala"><span style="color: #0000ff; font-weight: bold;">trait</span> Monad<span style="color: #F78811;">&#91;</span>M<span style="color: #F78811;">&#91;</span><span style="color: #000080;">_</span><span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#93;</span> <span style="color: #0000ff; font-weight: bold;">extends</span> Functor<span style="color: #F78811;">&#91;</span>M<span style="color: #F78811;">&#93;</span> <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> unit<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span>a<span style="color: #000080;">:</span> A<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> M<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> mult<span style="color: #F78811;">&#40;</span>m<span style="color: #000080;">:</span> M<span style="color: #F78811;">&#91;</span>M<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> M<span style="color: #F78811;">&#91;</span>A<span style="color: #F78811;">&#93;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>This would allow you derive <code>flatMap</code> as you have written.</p>
<p>Alternatively, <code>mult</code> can be derived: <code>m => m.flatMap(x => x)</code>. I have no particular preference for either representation, though I suspect there are ultimately practical implications. I&#8217;d be interested in knowing if this intuition is correct.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marius Danciu</title>
		<link>http://blog.tmorris.net/monad-exercises-in-scala/#comment-42025</link>
		<dc:creator>Marius Danciu</dc:creator>
		<pubDate>Fri, 18 Jun 2010 09:55:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=716#comment-42025</guid>
		<description>Hi Tony,

One thing I'm puzzled about


trait Monad[M[_]] {
  def flatMap[A, B](a: M[A], f: A =&#62; M[B]): M[B]
  def unital[A](a: A): M[A]
}


afaik a Monad is a tripple of (endo)functor and two natural transformations (unit and mult). These natural transformations are morphisms between functors (regardless if we represent them as in category theory or as Haskell does) but M[_] is not necessarily a functor. Therefore a call to Monad.flatMap or unital doesn't really bring us back automatically into the functors space, unless we wrap them again by other monad.

Of course List, Option etc are monadic but for the purpose of generalization I'd appreciate if you could clarify this for me.

I wonder about this form:

trait M[A] {

  def map[B](f: A =&#62; B) : M[B]
  def flatMap[B]( f: A =&#62; M[B]): M[B] = mult ( map ( f )  )

  def unit(a: A): M[A]
  def mult(m: M[M[a]]); M[a]
  
  protected def A get
}

Any thoughts?

Br's,
Marius</description>
		<content:encoded><![CDATA[<p>Hi Tony,</p>
<p>One thing I&#8217;m puzzled about</p>
<p>trait Monad[M[_]] {<br />
  def flatMap[A, B](a: M[A], f: A =&gt; M[B]): M[B]<br />
  def unital[A](a: A): M[A]<br />
}</p>
<p>afaik a Monad is a tripple of (endo)functor and two natural transformations (unit and mult). These natural transformations are morphisms between functors (regardless if we represent them as in category theory or as Haskell does) but M[_] is not necessarily a functor. Therefore a call to Monad.flatMap or unital doesn&#8217;t really bring us back automatically into the functors space, unless we wrap them again by other monad.</p>
<p>Of course List, Option etc are monadic but for the purpose of generalization I&#8217;d appreciate if you could clarify this for me.</p>
<p>I wonder about this form:</p>
<p>trait M[A] {</p>
<p>  def map[B](f: A =&gt; B) : M[B]<br />
  def flatMap[B]( f: A =&gt; M[B]): M[B] = mult ( map ( f )  )</p>
<p>  def unit(a: A): M[A]<br />
  def mult(m: M[M[a]]); M[a]</p>
<p>  protected def A get<br />
}</p>
<p>Any thoughts?</p>
<p>Br&#8217;s,<br />
Marius</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://blog.tmorris.net/monad-exercises-in-scala/#comment-39349</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Wed, 07 Apr 2010 07:57:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=716#comment-39349</guid>
		<description>My answers:

http://paste.pocoo.org/show/198673/</description>
		<content:encoded><![CDATA[<p>My answers:</p>
<p><a href="http://paste.pocoo.org/show/198673/" onclick="javascript:pageTracker._trackPageview('/outbound/comment/paste.pocoo.org');" rel="nofollow">http://paste.pocoo.org/show/198673/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: λ Tony’s blog λ &#187; Blog Archive &#187; Monad Exercises in Scala (addendum)</title>
		<link>http://blog.tmorris.net/monad-exercises-in-scala/#comment-39191</link>
		<dc:creator>λ Tony’s blog λ &#187; Blog Archive &#187; Monad Exercises in Scala (addendum)</dc:creator>
		<pubDate>Sat, 03 Apr 2010 05:45:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=716#comment-39191</guid>
		<description>[...] harness that should print a series of PASS when executed against a correct solution to the original Monad Exercises in Scala. These exercises include a Haskell version and a test harness for this is also found [...]</description>
		<content:encoded><![CDATA[<p>[...] harness that should print a series of PASS when executed against a correct solution to the original Monad Exercises in Scala. These exercises include a Haskell version and a test harness for this is also found [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/monad-exercises-in-scala/#comment-39053</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Mon, 29 Mar 2010 23:16:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=716#comment-39053</guid>
		<description>Hi Mark, You're right. Thanks for the correction.</description>
		<content:encoded><![CDATA[<p>Hi Mark, You&#8217;re right. Thanks for the correction.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Harris</title>
		<link>http://blog.tmorris.net/monad-exercises-in-scala/#comment-39050</link>
		<dc:creator>Mark Harris</dc:creator>
		<pubDate>Mon, 29 Mar 2010 22:17:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=716#comment-39050</guid>
		<description>I worked on the Haskell version of this challenge off and on over the weekend, and after losing most of it trying to make head or tail of Inter, finally ploughed through 4-11 in an hour or so tonight. Thank you for an interesting couple of days.

12, however, has me in a bit of a quandry. Hopefully, the type signature should be:

lift2 :: Monad' m -&#62; (a -&#62; b -&#62; c) -&#62; m a -&#62; m b -&#62; m c

Otherwise, any hints would be gratefully received.</description>
		<content:encoded><![CDATA[<p>I worked on the Haskell version of this challenge off and on over the weekend, and after losing most of it trying to make head or tail of Inter, finally ploughed through 4-11 in an hour or so tonight. Thank you for an interesting couple of days.</p>
<p>12, however, has me in a bit of a quandry. Hopefully, the type signature should be:</p>
<p>lift2 :: Monad&#8217; m -&gt; (a -&gt; b -&gt; c) -&gt; m a -&gt; m b -&gt; m c</p>
<p>Otherwise, any hints would be gratefully received.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: oxbow</title>
		<link>http://blog.tmorris.net/monad-exercises-in-scala/#comment-39037</link>
		<dc:creator>oxbow</dc:creator>
		<pubDate>Mon, 29 Mar 2010 12:23:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/?p=716#comment-39037</guid>
		<description>Thanks Tony - my current "Friday project" is to understand the Scalaz library. Think I've got these in the end, with some help from the mailing List. Didn't realize I could do stuff like *create* new lists (d'oh!)

Also watched the Nick Partridge video which you posted - very good. I'm not alone in failing to make the leap between some of the scalaz examples and what this looks like in real code. The best "a ha" moment so far was Nick's explanation of using validation with the  methods.

I also watched your "Monad" presentation and you urge people to play around as then they will discover the usages for themselves. I think a worked example of the introduction of some of these concepts to how a "standard Java guy" might write a small program would be really beneficial in this. But keep up the good work</description>
		<content:encoded><![CDATA[<p>Thanks Tony - my current &#8220;Friday project&#8221; is to understand the Scalaz library. Think I&#8217;ve got these in the end, with some help from the mailing List. Didn&#8217;t realize I could do stuff like *create* new lists (d&#8217;oh!)</p>
<p>Also watched the Nick Partridge video which you posted - very good. I&#8217;m not alone in failing to make the leap between some of the scalaz examples and what this looks like in real code. The best &#8220;a ha&#8221; moment so far was Nick&#8217;s explanation of using validation with the  methods.</p>
<p>I also watched your &#8220;Monad&#8221; presentation and you urge people to play around as then they will discover the usages for themselves. I think a worked example of the introduction of some of these concepts to how a &#8220;standard Java guy&#8221; might write a small program would be really beneficial in this. But keep up the good work</p>
]]></content:encoded>
	</item>
</channel>
</rss>

