<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Making a monad: Martin Erwig&#8217;s Dist</title>
	<atom:link href="http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/feed/" rel="self" type="application/rss+xml" />
	<link>http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/</link>
	<description>Haskell programming journal</description>
	<lastBuildDate>Fri, 17 May 2013 21:48:47 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: a dayvan cowboy &#187; Blog Archive &#187; Blast from the past: a stochastic monad in Haskell</title>
		<link>http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-3082</link>
		<dc:creator><![CDATA[a dayvan cowboy &#187; Blog Archive &#187; Blast from the past: a stochastic monad in Haskell]]></dc:creator>
		<pubDate>Fri, 08 May 2009 20:06:26 +0000</pubDate>
		<guid isPermaLink="false">http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-3082</guid>
		<description><![CDATA[[...] originally posted this online in february 2007 in a long-abandoned blog about Haskell programming. Gosh, my brainpower is clearly declining. By all means check the comments as well; the Haskell [...]]]></description>
		<content:encoded><![CDATA[<p>[...] originally posted this online in february 2007 in a long-abandoned blog about Haskell programming. Gosh, my brainpower is clearly declining. By all means check the comments as well; the Haskell [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harald Korneliussen</title>
		<link>http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-401</link>
		<dc:creator><![CDATA[Harald Korneliussen]]></dc:creator>
		<pubDate>Fri, 16 Feb 2007 12:10:46 +0000</pubDate>
		<guid isPermaLink="false">http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-401</guid>
		<description><![CDATA[Having this in the standard libraries would be great. Whether it should go in &quot;Control&quot; or &quot;Data&quot; I have no idea.]]></description>
		<content:encoded><![CDATA[<p>Having this in the standard libraries would be great. Whether it should go in &#8220;Control&#8221; or &#8220;Data&#8221; I have no idea.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-384</link>
		<dc:creator><![CDATA[Steve]]></dc:creator>
		<pubDate>Mon, 12 Feb 2007 01:48:08 +0000</pubDate>
		<guid isPermaLink="false">http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-384</guid>
		<description><![CDATA[I was Martin Erwig&#039;s grad student and this was actually my Master&#039;s thesis that we did together.  You can read the thesis at http://www.kolls.net/cv/mythesis.pdf

We also applied the approach to biological modeling, as can be found in the paper &quot;Modeling Genome Evolution with a DSEL for Probabilistic Programming&quot; which made LtU back when it was fresh.  This one is also on the website.]]></description>
		<content:encoded><![CDATA[<p>I was Martin Erwig&#8217;s grad student and this was actually my Master&#8217;s thesis that we did together.  You can read the thesis at <a href="http://www.kolls.net/cv/mythesis.pdf" rel="nofollow">http://www.kolls.net/cv/mythesis.pdf</a></p>
<p>We also applied the approach to biological modeling, as can be found in the paper &#8220;Modeling Genome Evolution with a DSEL for Probabilistic Programming&#8221; which made LtU back when it was fresh.  This one is also on the website.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cale Gibbard</title>
		<link>http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-381</link>
		<dc:creator><![CDATA[Cale Gibbard]]></dc:creator>
		<pubDate>Sun, 11 Feb 2007 21:57:55 +0000</pubDate>
		<guid isPermaLink="false">http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-381</guid>
		<description><![CDATA[I also just noticed that it obliterated my indentation... but at least in this case, the right indentation should be obvious, and I wouldn&#039;t know what markup to use in order to get whitespace preservation anyway.

&#160;&#160;&#160;&#160;Does nbsp work? (testing)]]></description>
		<content:encoded><![CDATA[<p>I also just noticed that it obliterated my indentation&#8230; but at least in this case, the right indentation should be obvious, and I wouldn&#8217;t know what markup to use in order to get whitespace preservation anyway.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;Does nbsp work? (testing)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cale Gibbard</title>
		<link>http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-380</link>
		<dc:creator><![CDATA[Cale Gibbard]]></dc:creator>
		<pubDate>Sun, 11 Feb 2007 21:54:43 +0000</pubDate>
		<guid isPermaLink="false">http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-380</guid>
		<description><![CDATA[Ack! Bitten by the same problem! Bad software! Bad!

Here&#039;s the last bit of my code again with the less-than replaced by the unicode symbol &quot;precedes&quot;

die = optionP [(n,1/6) &#124; n ≺- [1..6]]
test = collect $ liftM2 (+) die die]]></description>
		<content:encoded><![CDATA[<p>Ack! Bitten by the same problem! Bad software! Bad!</p>
<p>Here&#8217;s the last bit of my code again with the less-than replaced by the unicode symbol &#8220;precedes&#8221;</p>
<p>die = optionP [(n,1/6) | n ≺- [1..6]]<br />
test = collect $ liftM2 (+) die die</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cale Gibbard</title>
		<link>http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-379</link>
		<dc:creator><![CDATA[Cale Gibbard]]></dc:creator>
		<pubDate>Sun, 11 Feb 2007 21:52:24 +0000</pubDate>
		<guid isPermaLink="false">http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-379</guid>
		<description><![CDATA[By the way, there&#039;s a much faster way to construct that monad. You can also get it by Writer transforming the list monad with your probability representation type, and define an instance of Monoid for probabilities where the operation is just multiplication. It&#039;s fun to play around with. I ran into it while modelling probabilistic L-systems quite a while ago.

{-# OPTIONS_GHC -fglasgow-exts #-}
import Control.Monad.Writer
import Data.Ratio
import Data.Monoid
import qualified Data.Map as M

newtype Dist a = D (WriterT Probability [] a)
   deriving (Functor, Monad)

newtype Probability = P Rational 
   deriving (Eq, Ord, Show, Num, Fractional)

instance Monoid Probability where
   mempty = 1
   mappend = (*)
   mconcat = product

runDist :: Dist a -&gt; [(a, Probability)]
runDist (D x) = runWriterT x

optionP :: [(a, Probability)] -&gt; Dist a
optionP xs = D (WriterT xs)

(??) p = sum . map snd . filter (p . fst) . runDist

collect :: (Ord a) =&gt; Dist a -&gt; Dist a
collect x = optionP . M.toList . M.fromListWith (+) $ runDist x

die = optionP [(n,1/6) &#124; n ]]></description>
		<content:encoded><![CDATA[<p>By the way, there&#8217;s a much faster way to construct that monad. You can also get it by Writer transforming the list monad with your probability representation type, and define an instance of Monoid for probabilities where the operation is just multiplication. It&#8217;s fun to play around with. I ran into it while modelling probabilistic L-systems quite a while ago.</p>
<p>{-# OPTIONS_GHC -fglasgow-exts #-}<br />
import Control.Monad.Writer<br />
import Data.Ratio<br />
import Data.Monoid<br />
import qualified Data.Map as M</p>
<p>newtype Dist a = D (WriterT Probability [] a)<br />
   deriving (Functor, Monad)</p>
<p>newtype Probability = P Rational<br />
   deriving (Eq, Ord, Show, Num, Fractional)</p>
<p>instance Monoid Probability where<br />
   mempty = 1<br />
   mappend = (*)<br />
   mconcat = product</p>
<p>runDist :: Dist a -&gt; [(a, Probability)]<br />
runDist (D x) = runWriterT x</p>
<p>optionP :: [(a, Probability)] -&gt; Dist a<br />
optionP xs = D (WriterT xs)</p>
<p>(??) p = sum . map snd . filter (p . fst) . runDist</p>
<p>collect :: (Ord a) =&gt; Dist a -&gt; Dist a<br />
collect x = optionP . M.toList . M.fromListWith (+) $ runDist x</p>
<p>die = optionP [(n,1/6) | n </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas</title>
		<link>http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-378</link>
		<dc:creator><![CDATA[Thomas]]></dc:creator>
		<pubDate>Sun, 11 Feb 2007 21:37:12 +0000</pubDate>
		<guid isPermaLink="false">http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-378</guid>
		<description><![CDATA[D&#039;Oh. Your comment function chokes on &quot;&lt;&quot;.  Hence my chopped-off comment.  So, I repeat, looks like it&#039;s going to become a very useful library, go ahead!]]></description>
		<content:encoded><![CDATA[<p>D&#8217;Oh. Your comment function chokes on &#8220;&lt;&#8221;.  Hence my chopped-off comment.  So, I repeat, looks like it&#8217;s going to become a very useful library, go ahead!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thedward</title>
		<link>http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-377</link>
		<dc:creator><![CDATA[thedward]]></dc:creator>
		<pubDate>Sun, 11 Feb 2007 21:31:20 +0000</pubDate>
		<guid isPermaLink="false">http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-377</guid>
		<description><![CDATA[Would there be any disadvantage to using a Ratio instead of a Float for the probability values aside from the speed hit? 

Using ratios would seem a lot more intuitive to me. I&#039;d rather see 1%6 instead of 16.7% for the probability of any given number on a six sided die.

Might it make sense to parameterize the Probability class so it could use any of the Fractional numbers? (Probability Float, or Probability Rational, etc)]]></description>
		<content:encoded><![CDATA[<p>Would there be any disadvantage to using a Ratio instead of a Float for the probability values aside from the speed hit? </p>
<p>Using ratios would seem a lot more intuitive to me. I&#8217;d rather see 1%6 instead of 16.7% for the probability of any given number on a six sided die.</p>
<p>Might it make sense to parameterize the Probability class so it could use any of the Fractional numbers? (Probability Float, or Probability Rational, etc)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Thomas</title>
		<link>http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-376</link>
		<dc:creator><![CDATA[Thomas]]></dc:creator>
		<pubDate>Sun, 11 Feb 2007 20:10:08 +0000</pubDate>
		<guid isPermaLink="false">http://syntaxfree.wordpress.com/2007/02/11/making-a-monad-martin-erwigs-dist/#comment-376</guid>
		<description><![CDATA[I am confused, how does this typecheck?

&gt; dice = D [(1,1/6), (2,1/6), (3,1/6),(4,1/6),(5,1/6),(6/16)]

It&#039;s either a weird (DWIM-eval) typo or it really works, since you also wrote this:

&gt; fmap (*2) dice == D [ 2*x, p &#124; (x,p) ]]></description>
		<content:encoded><![CDATA[<p>I am confused, how does this typecheck?</p>
<p>&gt; dice = D [(1,1/6), (2,1/6), (3,1/6),(4,1/6),(5,1/6),(6/16)]</p>
<p>It&#8217;s either a weird (DWIM-eval) typo or it really works, since you also wrote this:</p>
<p>&gt; fmap (*2) dice == D [ 2*x, p | (x,p) </p>
]]></content:encoded>
	</item>
</channel>
</rss>
