<?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/"
	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>tech guy in midtown &#187; learning</title>
	<atom:link href="http://techguyinmidtown.com/tag/learning/feed/" rel="self" type="application/rss+xml" />
	<link>http://techguyinmidtown.com</link>
	<description>the notebook of a computer scientist living in midtown manhattan</description>
	<lastBuildDate>Mon, 12 Dec 2011 06:38:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='techguyinmidtown.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>tech guy in midtown &#187; learning</title>
		<link>http://techguyinmidtown.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://techguyinmidtown.com/osd.xml" title="tech guy in midtown" />
	<atom:link rel='hub' href='http://techguyinmidtown.com/?pushpress=hub'/>
		<item>
		<title>My Answers to the Microsoft Interview Questions</title>
		<link>http://techguyinmidtown.com/2008/07/05/my-answers-to-the-microsoft-interview-questions/</link>
		<comments>http://techguyinmidtown.com/2008/07/05/my-answers-to-the-microsoft-interview-questions/#comments</comments>
		<pubDate>Sat, 05 Jul 2008 22:21:32 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[interviewing]]></category>
		<category><![CDATA[learning]]></category>

		<guid isPermaLink="false">http://techguyinmidtown.wordpress.com/?p=25</guid>
		<description><![CDATA[I thought it would be fun to write up solutions to the Microsoft interview questions that Andrew Wagner (chessguy) posted to the Haskell Cafe mailing list. I read about his post in the Haskel Sequence weekly news of June 25, 2008. You can read his post here. &#62; module Questions &#62; where &#62; import Data.Array [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techguyinmidtown.com&amp;blog=3566010&amp;post=25&amp;subd=techguyinmidtown&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I thought it would be fun to write up solutions to the Microsoft interview questions that Andrew Wagner (chessguy) posted to the Haskell Cafe mailing list.  I read about his post in the Haskel Sequence weekly news of June 25, 2008.  You can read his post <a href="http://article.gmane.org/gmane.comp.lang.haskell.cafe/41760">here</a>.</p>
<pre>
&gt; module Questions
&gt; where

&gt; import Data.Array
&gt; import Data.List
&gt; import Random
</pre>
<p><i>1.) A &#8220;rotated array&#8221; is an array of integers in ascending order, after which for every element i, it has been moved to element (i + n) mod sizeOfList. Write a function that takes a rotated array and, in less-than-linear time, returns n (the amount of rotation). </i></p>
<p>First we&#8217;ll write a simple function to rotate a given array (xs) by a given amount (n).</p>
<pre>
&gt; rotate n xs = b ++ a
&gt;     where n'     = n `mod` (length xs)
&gt;           (a, b) = splitAt ((length xs) - n') xs
</pre>
<p>Now we turn to the function that computes how much the array was rotated.  The key to the solution is realizing that you need to find an inflection point where consecutive numbers in the rotated list decrease.  To do this, we find the first, largest sub-sequence that monotonically increases.  We can find that subsequence using binary search, testing the endpoints of subsequences.  The running time is O(log(n)), where n is the length of the input list (ignoring the O(n) time to construct our array).</p>
<pre>
&gt; rotateAmount xs = _ra 0 ((length xs) - 1) (listArray (0, ((length xs) - 1)) xs)
&gt;     where _ra s e ys = if (e - s) == 1
&gt;                        then (if ((ys ! s) &amp;lt (ys ! e)) then s else e)  -- base case
&gt;                        else let h  = ys ! s                  -- first item
&gt;                                 l  = ys ! e                  -- last item
&gt;                                 mi = s + ((e - s) `div` 2)   -- middle index
&gt;                                 m  = ys ! mi                 -- middle item
&gt;                             in if (h &amp;lt l)
&gt;                                then s                        -- return start index
&gt;                                else if (h &amp;gt m)
&gt;                                     then _ra s  mi ys
&gt;                                     else _ra mi e  ys
</pre>
<p><i>2.) You are given a list of Ball objects. Each Ball is either Red or Blue. Write a function that partitions these balls so that all of the balls of each color are contiguous. Return the index of the first ball of the second color (your result can be Red balls, then Blue balls, or the other way around). In haskell, you&#8217;ll probably want to return a ([Ball],Int).</i></p>
<p>This one is dead-simple in Haskell.</p>
<pre>
&gt; data Ball = Red | Blue deriving (Eq, Ord, Show, Read)

&gt; groupBalls bs = let gs = (group . sort) bs
&gt;                 in (concat gs, length $ head gs)
</pre>
<p><i>3.) Live Search is a search engine. Suppose it was to be tied into an online store. Now you&#8217;re given two lists. One is a [(SessionId, NormalizedQuery)]. That is, when a particular user performs a query, it is turned into some consistent format, based on their apparent intent, and stored in this logfile. The second list is a [(SessionId, ProductId)]. This indicates the product bought by a particular user.  Now, you want to take these two (potentially very long) lists, and return some structure that will make it easy to take a query and return a list of the most popular resulting purchases. That is, of people who have run this query in the past, what are the most common products they&#8217;ve wound up buying? The interviewer said that this is an instance of a well-known problem, but I didn&#8217;t catch the name of it.<br />
</i></p>
<p>I&#8217;m skipping this for now because its more of a rambling thought experiment.  I&#8217;d love to chat about it, but I&#8217;m not going to immediately dive into writing some code.</p>
<p><i>4.) You&#8217;re given an array which contains the numbers from 1 to n, in random order, except there is one missing. Write a function to return the missing number.</i></p>
<p>Obviously sorting and walking through would work, but we can do better because the sum of the numbers 1 through n is (n * (n+1) / 2).  So we can get it in one pass.  This takes O(n) time.  Neat.</p>
<pre>
&gt; missingInt xs = let n = length xs
&gt;                 in ((n + 1) * (n + 2) `div` 2) - (sum xs)
</pre>
<p><i><br />
5.) Write a function to reconstruct a binary tree from its preorder traversal and inorder traversal. Take into account that the traversals could be invalid.</i></p>
<p>First define a tree data structure.</p>
<pre>
&gt; data Tree a = Tree a (Tree a) (Tree a) | Leaf a | Empty
&gt;               deriving (Eq, Ord, Show, Read)
</pre>
<p>For the pre-order list we need to split it up by what elements are less than or greater than the head of the list (thinking recursively here).  So in the initial list, the first element is the root, and then the subsequent items that are less than the first element are in the left branch, and the other items are in the right branch.  I don&#8217;t catch invalid traversals, although they would show up if &#8216;rest2&#8242; in the below function was not empty.</p>
<pre>
&gt; preorderTree xs = f xs
&gt;     where f []          = Empty
&gt;           f (h:[])      = Leaf h
&gt;           f (h:tl)      = let (left,  rest1) = span (&amp;lt h) tl
&gt;                               (right, rest2) = span (&amp;gt h) rest1
&gt;                           in Tree h (f left) (f right)

&gt; po1 = [4, 2, 1, 3, 5, 6]   -- test
</pre>
<p>Now, for the in-order traversal, every input will simply be an in-order list of numbers.  So we create a balanced binary tree using that traversal by recursively splitting the list in half.</p>
<pre>
&gt; inorderTree xs = f xs
&gt;     where f [] = Empty
&gt;           f (h:[]) = Leaf h
&gt;           f (h1:h2:[]) = Tree h2 (Leaf h1) Empty
&gt;           f ys = let (left, right) = splitAt ((length ys) `div` 2) ys
&gt;                  in Tree (head right) (f left) (f $ tail right)

&gt; pi1 = [1..6]
</pre>
<p><i>6.) You have a [(WeatherStationId, Latitude, Longitude)]. Similar to #3, write a function which will, off-line, turn this into a data structure from which you can easily determine the nearest Weather Station, given an arbitrary Latitude and Longitude.</i></p>
<p>I&#8217;m fairly stumped by this one.  I can think of good ways to to solve this problem conceptualy, but I can&#8217;t think of a simple data structure to return. I&#8217;d like to return a data structure of polygons, where each polygon encapsulates what points are closest to each weather station.  I don&#8217;t feel like coding that up though.</p>
<p><i>7.) Write a function for scoring a mastermind guess. That is, in a game of mastermind (http://en.wikipedia.org/wiki/Mastermind_(board_game)), given a guess, and the actual answer, determine the number correct, the number wrong,and the number out of place.</i></p>
<p> For this solution, we zip up the answer and the guess so we can examine the elements pair-wise.  We then consider each pair.  If they are equal, we can increment a correct counter.  Otherwise, we must accumulate a list of incorrect values.  As we build up the incorrect values, we check if each guess and answer has already been accumulated in the list of incorrect values.  When we find it in the accumulated list, we know we&#8217;ve found a guess that was in the wrong position.</p>
<pre>

&gt; data ColoredPeg = W | G | B | R | P | O deriving (Eq, Ord, Show, Read)

&gt; scoreMM as gs = let (crct, wrg, _) = foldl f (0, [], []) (zip as gs)
&gt;                     wrongPosition = (length as) - crct - (length wrg)
&gt;                 in (crct, (length wrg), wrongPosition)
&gt;     where f (c, oA, oG)
&gt;                 (a, g) = case g == a of  -- update an accumulator after examining each pair
&gt;                          True -&gt; (c+1, oA, oG) -- match, so simply update the count of correct
&gt;                          False -&gt; case ((a `elem` oG), (g `elem` oA)) of
&gt;                               (True,True)-&gt;(c, (rem g oA), (rem a oG))
&gt;                               (False,True)-&gt;(c, a:(rem g oA), (rem a oG))
&gt;                               (True,False)-&gt;(c, (rem g oA), g:(rem a oG))
&gt;                               (False,False)-&gt;(c, a:(rem g oA), g:(rem a oG))
&gt;           rem a [] = []
&gt;           rem a (b:bs) = if (a == b) then bs else b:(rem a bs)

&gt; testAnswer1 = [W, G, B, R]
&gt; testGuess1 = [W, G, R, B]
&gt; testGuess2 = [W, G, R, P]
</pre>
<p><i>8.) Implement a trie (http://en.wikipedia.org/wiki/Trie) data structure. Write a function add, which takes a word, and a trie, and adds the word to the trie. Write another function lookup, which takes a prefix and a trie, and returns all the words in the trie that start with that prefix.</i></p>
<p>This is a fairly straightforward problem.  We create the Trie data structure and define the recursive functions.  I wish that we didn&#8217;t have a special data value for the Trie root, but I couldn&#8217;t think of an alternate solution besides having a special null character as the root.</p>
<pre>

&gt; data Trie = TrieRoot { tries :: [Trie] }
&gt;     | Trie { char :: Char, tries :: [Trie] }
&gt;             deriving (Eq, Ord, Show, Read)

&gt; trieAdd t [] = t
&gt; trieAdd (TrieRoot ts) ws = TrieRoot{tries = (_tahelp ts ws)}
&gt; trieAdd (Trie c ts) ws   = Trie{char = c, tries = (_tahelp ts ws)}
&gt; _tahelp ts (w:ws) = case find (\t -&gt; (char t) == w) ts of
&gt;                     Nothing -&gt; let newTrie = trieAdd Trie{char=w,
&gt;                                                           tries=[]} ws
&gt;                                in newTrie:ts
&gt;                     Just mtch -&gt; let otherTries = filter (\t -&gt; (char t) /= w) ts
&gt;                                      newTrie    = trieAdd mtch ws
&gt;                                  in newTrie:otherTries

&gt; trieLookup (TrieRoot ts) ws = concatMap (\t -&gt; trieLookup t ws) ts
&gt; trieLookup (Trie c ts) [] = case ts of
&gt;                             []        -&gt; [[c]]
&gt;                             otherwise -&gt; recurse
&gt;     where recurse = map (\str -&gt; c:str) $ concatMap (\t -&gt; trieLookup t []) ts
&gt; trieLookup (Trie c ts) (w:ws) = if (c == w)
&gt;                                 then case ts of -- we matched the character
&gt;                                      []        -&gt; [[c]]
&gt;                                      otherwise -&gt; recurse
&gt;                                 else [] -- stop the search down this trie branch
&gt;     where recurse = map (\str -&gt; c:str) $ concatMap (\t -&gt; trieLookup t ws) ts

&gt; testTrie = trieAdd (trieAdd (trieAdd (TrieRoot []) "hi") "hot") "gr"
&gt; testTrie2 = trieAdd (TrieRoot []) "h"
</pre>
<p><i>9.) Write an algorithm to shuffle a deck of cards. Now write a function to perform some kind of evaluation of &#8220;how shuffled&#8221; a deck of cards is.</i></p>
<p>To shuffle I swap element i with a random element at position [i, (n-1)].</p>
<pre>
&gt; shuffle gen xs = let n = length xs
&gt;                      a = listArray (0, (n - 1)) xs                 -- create an Array
&gt;                      swapPairs = (zip [0..(n - 1)] (swaps gen n))  -- compute a sequence of swaps to perform
&gt;                  in elems $ foldl f a swapPairs
&gt;     where f a' (i1, i2) = a' // [(i1, a'!i2), (i2, a'!i1)]         -- swap element at i1 with element at i2
</pre>
<p>Here&#8217;s a function which generates a sequence of swaps.  We swap element at index &#8216;i&#8217; into the range [i, (n-1)].  </p>
<pre>
&gt; swaps gen n = unfoldr f (gen, 0)
&gt;     where f (g, i) = if (i &amp;lt n)
&gt;                      then let (randInt, g') = next g
&gt;                               swapIndex = (randInt `mod` (n - i)) + i  -- produce a number in [i, (n-1)]
&gt;                           in Just (swapIndex, (g', (i+1)))         -- add 'swapIndex' to the generated list
&gt;                      else Nothing                                  -- stop generating elements
</pre>
<p>Here are functions that generates a sequence of random numbers or random generators.  Can be used to call shuffle multiple times.</p>
<pre>
&gt; randomGems = map mkStdGen randomNums
&gt; randomNums = unfoldr (Just . next) (mkStdGen 1)
</pre>
<p>One way we might measure how good the suffle is (although for a single shuffle, the question is a bit preposterous), is to compute the min, max, and average distance that each item moved in the list.</p>
<pre>

&gt; shuffleQuality xs ys = let xsPos = sortBySnd $ zip [1..(length xs)] xs
&gt;                            ysPos = sortBySnd $ zip [1..(length ys)] ys
&gt;                            diffFun = (\ (xp, yp) -&gt; abs ((fst xp) - (fst yp)))
&gt;                            posDiffs = map diffFun (zip xsPos ysPos)
&gt;                            maxDiff = maximum posDiffs
&gt;                            minDiff = minimum posDiffs
&gt;                            avgDiff = (sum posDiffs) `div` (length posDiffs)
&gt;                        in (maxDiff, minDiff, avgDiff)
&gt;     where sortBySnd ps = sortBy (\ p1 p2 -&gt; compare (snd p1) (snd p2)) ps
</pre>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/techguyinmidtown.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/techguyinmidtown.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techguyinmidtown.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techguyinmidtown.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techguyinmidtown.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techguyinmidtown.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techguyinmidtown.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techguyinmidtown.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techguyinmidtown.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techguyinmidtown.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techguyinmidtown.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techguyinmidtown.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techguyinmidtown.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techguyinmidtown.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techguyinmidtown.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techguyinmidtown.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techguyinmidtown.com&amp;blog=3566010&amp;post=25&amp;subd=techguyinmidtown&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techguyinmidtown.com/2008/07/05/my-answers-to-the-microsoft-interview-questions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92ebb01dce9310ed1f6898975c14ea23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
		<item>
		<title>Monads Demystified</title>
		<link>http://techguyinmidtown.com/2008/05/20/monads-demystified/</link>
		<comments>http://techguyinmidtown.com/2008/05/20/monads-demystified/#comments</comments>
		<pubDate>Tue, 20 May 2008 04:05:35 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[learning]]></category>

		<guid isPermaLink="false">http://techguyinmidtown.wordpress.com/?p=14</guid>
		<description><![CDATA[Haskell&#8217;s monads are an enigma. They hold the key to shorter, more modular Haskell programs, but at first they&#8217;re hard to understand. For sure, many monadic tutorials exist, but I had to study them for weeks before it all clicked. I know others who struggled just as much. I had such a hard time partly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techguyinmidtown.com&amp;blog=3566010&amp;post=14&amp;subd=techguyinmidtown&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Haskell&#8217;s monads are an enigma.  They hold the key to shorter, more modular Haskell programs, but at first they&#8217;re hard to understand.  For sure, many monadic tutorials exist, but I had to study them for weeks before it all clicked.  I know others who struggled just as much.</p>
<p>I had such a hard time partly because I didn&#8217;t understand some fundamental concepts as well as I had thought.  Unfortunately, it took me a while to realize this because I already had experience writing real Haskell code.  It didn&#8217;t occur to me that I had to revisit basic concepts like types and functions.  I also think that other tutorials don&#8217;t spend enough time breaking down the syntactic sugar that makes Haskell&#8217;s monads so terse.</p>
<p>This writeup focuses on the concepts that confused me. The intended audience is people who have studied Haskell, yet have struggled with monads.  Although some fundemental concepts are explained, this is not a comprehensive introduction to Haskell.</p>
<p>Before we dive in, I want to acknowledge a few people and resources that I found most helpful during my studies.  Paul Hudak&#8217;s writing is exceptionally lucid.  His original <a href="http://www.haskell.org/tutorial/monads.html">A Gentle Introduction to Haskell</a> is a tremendous resource.  Cale Gibbard wrote my two favorite monadic introductions: <a href="http://www.haskell.org/haskellwiki/Monads_as_Containers">Monads as Containers</a> and <a href="http://www.haskell.org/haskellwiki/Monads_as_computation">Monads as Computation.</a> In addition, Jeff Newbern&#8217;s <a href="http://www.haskell.org/all_about_monads/html/index.html">All About Monads</a> contains a well written Catalog of Standard Monads. Finally, the experts on the #haskell IRC channel are always helpful.</p>
<h3>Back to Basics</h3>
<p>Before we talk about the syntax or semantics of monads, and before we step through any examples, we go back to basics.  When I started learning about monads, I overestimated my understanding of Haskell&#8217;s type system.  This section highlights the concepts that I overlooked.</p>
<p>Every monad is nothing more than a paramaterized type that implements a few functions.  Let&#8217;s review paramaterized types by exploring the details of <code>(Maybe a)</code>.</p>
<pre>&gt; data Maybe a = Nothing
&gt;              | Just a</pre>
<p>It&#8217;s straightforward to see that <code>(Maybe a)</code> can be used to represent values that either exist or are missing.  It&#8217;s also intuitive that the variable <code>a</code> is a place holder for the type that may or may not be there (perhaps an <code>Int</code>).  Fair enough, but there&#8217;s more.</p>
<p>First let&#8217;s break down the type&#8217;s name.  Although it is often called the &#8220;maybe type&#8221; in conversation, its proper name is <code>(Maybe a)</code>.  The word <code>Maybe</code> is a <em>type constructor</em> and the character <code>a</code> is a <em>type variable</em>.</p>
<p>The type constructor <code>Maybe</code> is a function that accepts the given type variable <code>a</code> and returns the type <code>(Maybe a)</code>.  I found this notion confusing because you cannot call the <code>Maybe</code> function within regular code.  For example, <code>ghci</code> prints out:</p>
<pre>Prelude&gt; Maybe 4
:1:0: Not in scope: data constructor `Maybe'
Prelude&gt; :t Maybe
:1:0: Not in scope: data constructor `Maybe'
Prelude&gt; :kind Maybe
Maybe :: * -&gt; *</pre>
<p>The last statement, using <code>:kind</code>, gives an indication that <code>Maybe</code> is a unary type constructor.  We won&#8217;t stop to discuss notion of a kinds (partly because I don&#8217;t understand them well enough myself).  We can safely skip that topic.  The error messages are printed because the <code>Maybe</code> function is only valid within the context of type definitions, type class definitions, and type signatures. For example, you might write:</p>
<pre>&gt; catMaybes :: [Maybe a] -&gt; [a]</pre>
<p>Within this type signature, <code>Maybe</code> is a function being applied to the type variable <code>a</code>, to produce a type of <code>(Maybe a)</code>.  (Incidentally, the type <code>(Maybe a)</code> is passed in turn to the type constructor <code>[]</code>.) This is code, but it is within the scope of type signatures.  We&#8217;ll return to this distinction later when we replace particular type constructors like <code>Maybe</code> with a variable that represents any parametric type constructor.</p>
<p>The right hand side of the type definition lists one or more <em>value constructors</em>, separated by the pipe symbol.  For <code>(Maybe a)</code>, we have <code>Nothing</code> and <code>Just a</code>. Even though these value constructors are defined within the type definition, they are valid in regular Haskell code, as we can see with <code>ghci</code>:</p>
<pre>Prelude&gt; :t Nothing
Nothing :: Maybe a
Prelude&gt; :t Just
Just :: a -&gt; Maybe a
Prelude&gt; Just 5
Just 5</pre>
<p>The <code>ghci</code> output says that the function named <code>Just</code> takes some value <code>x</code> of type <code>a</code> and returns a value of type <code>(Maybe a)</code>, which by definition equals <code>Just x</code>.  We introduce the value variable <code>x</code> here to distinguish it from <code>a</code>, which is a type variable.  Similarly, <code>Nothing</code> is a nullary function of type <code>(Maybe a)</code>.</p>
<p>Note that unlike the type constructor <code>Maybe</code>, which produces a type named <code>(Maybe a)</code>, the value constructors <code>Nothing</code> and <code>Just</code> produce values that have the type <code>(Maybe a)</code>.  One consequence of this distinction is the tendency for value constructors to be named after its type constructor.  This is not a conflict because value constructors and type constructors are in different namespaces.</p>
<p>Finally, be sure to review the notion of Haskell type classes and instances.  Type classes allow us to define a particular interface, and then instances allow us to declare that a type implements that interface.  For the purposes of monads, we will be examining the type classes <code>Functor</code>, and <code>Monad</code>.</p>
<h3>Functors</h3>
<p>For whatever reason, I had it in my mind that I would put off learning about functors until I understood monads.  I wasn&#8217;t sure what a functor was, but I also wasn&#8217;t sure what a monad was, and I wanted to take things one at a time.  In retrospect, this was a foolish mistake because the concepts are related, and functors are much simpler than monads.</p>
<p>A functor is simply a fancy name for a type that supports the <code>map</code> function, which happens to be called <code>fmap</code> in the <code>Functor</code> class.  In <code>ghci</code> you can see:</p>
<pre>Prelude&gt; :t map
map :: (a -&gt; b) -&gt; [a] -&gt; [b]
Prelude&gt; :t fmap
fmap :: (Functor f) =&gt; (a -&gt; b) -&gt; f a -&gt; f b</pre>
<p>As the types show, the <code>map</code> function only operates over lists, whereas <code>fmap</code> is generalized to operate over any parametric type.  The idea is that we want to apply some function to every item within a collection.  The <code>Functor</code> class is defined as follows:</p>
<pre>&gt; class Functor f where
&gt;     fmap     :: (a -&gt; b) -&gt; f a -&gt; f b</pre>
<p>This type class definition is written in the language for types.  The variable <code>f</code> is a placeholder for any parametric type constructor.  We could instantiate the variable with any parametric type constructor, including <code>Maybe</code>.  For example:</p>
<pre>&gt; instance Functor Maybe where
&gt;     fmap f Nothing  = Nothing
&gt;     fmap f (Just x) = Just (f x)</pre>
<p>A minor point &#8212; do not let the reuse of the variable <code>f</code> confuse you.  In the <code>Functor</code> class definition, <code>f</code> is a placeholder for a type constructor. Within this instance defintion, <code>f</code> represents the function that we want to apply to whatever is within the <code>Just x</code> value.</p>
<p>Let&#8217;s see what happens in <code>ghci</code>:</p>
<pre>Prelude&gt; fmap (* 2) (Just 4)
Just 8
Prelude&gt; fmap (* 2) Nothing
Nothing
Prelude&gt; fmap odd (Just 4)
Just False
Prelude&gt; fmap odd Nothing
Nothing</pre>
<p>For the list type, we simply have:</p>
<pre>&gt; instance Functor [] where
&gt;     fmap = map</pre>
<p>To be precise, there are a two semantic rules that every proper <code>fmap</code> implementation must abide by:</p>
<pre>&gt; fmap id      = id
&gt; fmap (f . g) = fmap f . fmap g</pre>
<p>Together, these rules ensure that <code>fmap</code> doesn&#8217;t modify the shape or order of its input.  Most sensible definitions of <code>fmap</code> abide by these rules, so don&#8217;t think about them too hard.</p>
<p>The important takeway from this section is the generalization of <code>map</code> to any parametric type using the variable <code>f</code> within the type signature of <code>fmap</code>.  This allows us to make any parametric type (such as <code>[a]</code>) implement fmap, satisfying the common need of applying a function to every item in some collection.  In the case of <code>(Maybe a)</code>, we apply the function to zero or one values.  For lists (the <code>[a]</code> type), we apply the function to zero or more values.</p>
<h3>The Monad Type Class</h3>
<p>Now we turn to the <code>Monad</code> class.  Perhaps surprisingly, we&#8217;ll hold off discussing how monads can improve your Haskell code.  Instead, we simply introduce the methods of the <code>Monad</code> class, just as we did for the <code>Functor</code> class.  We also introduce Haskell&#8217;s special monadic syntactic sugar.</p>
<p>Here is the <code>Monad</code> class definition:</p>
<pre>&gt; infixl 1  &gt;&gt;, &gt;&gt;=
&gt; class  Monad m  where
&gt;     return   :: a -&gt; m a
&gt;     (&gt;&gt;=)    :: m a -&gt; (a -&gt; m b) -&gt; m b
&gt;     (&gt;&gt;)     :: m a -&gt; m b -&gt; m b
&gt;     fail     :: String -&gt; m a
&gt;     m &gt;&gt; k   =  m &gt;&gt;= \_ -&gt; k</pre>
<p>The type class&#8217;s two important functions are <code>return</code> and <code>(&gt;&gt;=)</code>, which is conversationally called &#8220;bind&#8221;.  The function <code>(&gt;&gt;)</code> is defined in terms of bind, and exists to simplify syntax. We&#8217;ll discuss <code>fail</code> later, but it&#8217;s typically used to handle exceptional results.</p>
<p>Don&#8217;t fall in the trap of trying to think about what each of these functions &#8220;typically do.&#8221;  The meaning is different for each instance of the <code>Monad</code> class.  We will examine particular implementations shortly.</p>
<p>First, let&#8217;s examine <code>return</code>.  Despite its name, it has nothing to do with the standard flow control keyword in other languages.  In Haskell it is not a keyword, and it is not a flow control operator.  Instead, <code>return</code> is a generalized value constructor, similar to how <code>fmap</code> was a genearlized version of <code>map</code>.  We can show this in <code>ghci</code>:</p>
<pre>Prelude&gt; :t Just
Just :: a -&gt; Maybe a
Prelude&gt; :t return
return :: (Monad m) =&gt; a -&gt; m a</pre>
<p>Both functions take a value of some type, call it <code>a</code>, and return a value of a type that is parameterized over <code>a</code>.  The <code>Just</code> function always returns a value of type <code>(Maybe a)</code>, whereas the <code>return</code> function can generate a value of any parameterized type that is an instance of the <code>Monad</code> class.  It is an alias for one or more of the type&#8217;s value constructors.  We&#8217;ll give use cases for <code>return</code> later, but for now understand that if you need to create a monad, you often use <code>return</code> instead of explicitly using the type&#8217;s value constructors.</p>
<p>Next, consider bind, or <code>(&gt;&gt;=)</code>.  It is very similar to the <code>fmap</code> function, as we can see in <code>ghci</code>:</p>
<pre>Prelude&gt; :t fmap
fmap :: (Functor f) =&gt; (a -&gt; b) -&gt; f a -&gt; f b
Prelude&gt; :t (&gt;&gt;=)
(&gt;&gt;=) :: (Monad m) =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
Prelude&gt; :t (flip (&gt;&gt;=))
(flip (&gt;&gt;=)) :: (Monad m) =&gt; (a -&gt; m b) -&gt; m a -&gt; m b</pre>
<p>Both functions operate over a function and a parameterized type. The first two arguments are flipped, but that&#8217;s a small matter of syntax.  Also, the functions have slightly different signatures, but the intent looks familiar.</p>
<p>Just like with <code>Functor</code>, there are also some rules that any well defined instance of the <code>Monad</code> class must define.</p>
<pre>&gt; return a &gt;&gt;= k                 = k a
&gt; m        &gt;&gt;= return            = m
&gt; xs       &gt;&gt;= return . f        = fmap f xs
&gt; m        &gt;&gt;= (\x -&gt; k x &gt;&gt;= h) = (m &gt;&gt;= k) &gt;&gt;= h</pre>
<p>As with the <code>fmap</code> rules, don&#8217;t think about these too hard.  The first two rules say that <code>return</code> doesn&#8217;t tinker its argument.  The third rule relates bind to <code>fmap</code>, as we hinted above.  The third rule is a sort of associativity.</p>
<p>Haskell provides special syntactic sugar for the bind operator within its <code>do</code> block.  Haskell performs the following two translations for us:</p>
<pre>&gt; do e1 ; e2         = e1 &gt;&gt;  e2
&gt; do p &lt;- e1 ; e2    = e1 &gt;&gt;= \p -&gt; e2</pre>
<p>In the second case, if <code>p</code> does not pattern match with e2, then <code>fail</code> is called.  These two translations allow us to write monadic code that implicitly calls the bind operator.  One effect of this notation is that the resulting code resembles typical more familiar imperative code, as we&#8217;ll see in the next section when we look at examples.</p>
<h3>Basic Example Monads</h3>
<p>Let&#8217;s make these monadic functions concrete by looking at two basic monads: <code>(Maybe a)</code> and <code>[a]</code>.  For some time, I was confused when familiar types like these were referred to as monads.  It wasn&#8217;t clear to me that any parametric type which implements the <code>Monad</code> class is always a monad.  The monadic functionality only shines we apply a monadic operator, such as bind, on a value with the monadic type.</p>
<h4>Monadic Maybe a</h4>
<p>Starting with <code>(Maybe a)</code>, we define the two key monadic operators as follows:</p>
<pre>&gt; instance Monad Maybe where
&gt;     return         = Just
&gt;     Nothing  &gt;&gt;= f = Nothing
&gt;     (Just x) &gt;&gt;= f = f x
&gt;     fail _         = Nothing</pre>
<p>The <code>return</code> function is simply an alias for the value constructor <code>Just</code>.  The binding operator always returns <code>Nothing</code> if the first argument is <code>Nothing</code>. Otherwise, we apply the given function <code>f</code> to the value <code>x</code> paramaterized by <code>Just</code> in the first argument.  Due to its type, the function <code>f</code> must return either <code>Just x'</code> or <code>Nothing</code>.</p>
<p>It&#8217;s helpful to think of this instance of the bind operator passing zero or more values from one function to the next.  As the type signature of <code>(&gt;&gt;=)</code> dictates, each function must produce a value of type <code>(Maybe a)</code>.  Consider the following example.</p>
<p>Suppose we want to define a decrement operator over the natural numbers (all integers greater than or equal to zero).  To seamlessly support inputs less than or equal to zero, we define our function as follows:</p>
<pre>&gt; decrementNat x | x &lt;= 0    = Nothing
&gt;                | otherwise = Just (x-1)</pre>
<p>Note that <code>decrementNat</code> has the desirable signature <code>a -&gt; Maybe a</code>.  Now we can use the monadic bind function to perform multiple decrements.  If we load the above function from a module <code>Foo</code> in <code>ghci</code>, we can write:</p>
<pre>*Foo&gt; Nothing &gt;&gt;= decrementNat
Nothing
*Foo&gt; Nothing &gt;&gt;= decrementNat &gt;&gt;= decrementNat
Nothing
*Foo&gt; Just 2 &gt;&gt;= decrementNat
Just 1
*Foo&gt; Just 2 &gt;&gt;= decrementNat &gt;&gt;= decrementNat
Just 0
*Foo&gt; Just 2 &gt;&gt;= decrementNat &gt;&gt;= decrementNat &gt;&gt;= decrementNat
Nothing</pre>
<p>We can also use the syntactic sugar of <code>do</code>, to write a function such as:</p>
<pre>&gt; decrementNat3 x = do x1 &lt;- decrementNat x
&gt;                      x2 &lt;- decrementNat x1
&gt;                      decrementNat x2</pre>
<p>Then, once again, in <code>ghci</code>, we can write:</p>
<pre>*Foo&gt; decrementNat3 2
Nothing
*Foo&gt; decrementNat3 5
Just 2</pre>
<p>Notice that once the bind function (as defined for the <code>(Maybe a)</code> type) encounters a <code>Nothing</code>, it forever generates a <code>Nothing</code>.  It short circuits. Otherwise, the incrementally smaller value is passed along the chain.</p>
<h4>Monadic List</h4>
<p>The list type is also an instance of the <code>Monad</code> type class, defined as follows:</p>
<pre>&gt; instance Monad [] where
&gt;     return x = [x]
&gt;     m &gt;&gt;= f  = concatMap f m
&gt;     fail _   = []</pre>
<p>Once again, <code>return</code> is an alias for the value constructor <code>[]</code>.  The bind operator is best conceptualized in two steps.  First, a 2d list (a list of lists) is created because the function <code>f</code> is applied to every element in the list <code>m</code>.  Remember that <code>f</code> creates a list.  Then all of those lists are concatenated together.</p>
<p>Consider a simple expression such as:</p>
<pre>Prelude&gt; [1,2] &gt;&gt;= (\x -&gt; return $ odd x)
[True,False]</pre>
<p>Alternatively, you could write:</p>
<pre>&gt; myodd = do x &lt;- [1,2]
&gt;            return $ odd x</pre>
<p>What exactly is going on here?  Remember that for lists, the bind operator is <code>concatMap</code>, and <code>return</code> is the list constructor.  We might also write it as:</p>
<pre>Prelude&gt; concatMap (return . odd) [1,2]
[True,False]</pre>
<p>So the short monadic bind expression applies the function <code>\x -&gt; return $ odd x</code> to both <code>1</code> and <code>2</code> to create <code>[True]</code> and <code>[False]</code>, which are then concatenated together.</p>
<p>We can expand this example to produce all pairs of a list <code>l</code>.</p>
<pre>&gt; allpairs l = do x &lt;- l
&gt;                 y &lt;- l
&gt;                 return (x, y)</pre>
<p>Note that in this case there are two chained calls to <code>concatMap</code>.</p>
<h4>To be continued. . .</h4>
<p>These are the basic ideas behind monads.  We have not covered the type class <code>MonadPlus</code>.  We have also not explored many common instances of the <code>Monad</code> class, most notably <code>(IO a)</code> and <code>(State a)</code>.  Perhaps I&#8217;ll tackle those topics in a subsequent posts.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/techguyinmidtown.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/techguyinmidtown.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techguyinmidtown.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techguyinmidtown.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techguyinmidtown.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techguyinmidtown.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techguyinmidtown.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techguyinmidtown.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techguyinmidtown.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techguyinmidtown.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techguyinmidtown.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techguyinmidtown.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techguyinmidtown.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techguyinmidtown.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techguyinmidtown.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techguyinmidtown.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techguyinmidtown.com&amp;blog=3566010&amp;post=14&amp;subd=techguyinmidtown&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techguyinmidtown.com/2008/05/20/monads-demystified/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92ebb01dce9310ed1f6898975c14ea23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
		<item>
		<title>Remarks on Language Dabbling Considered Wasteful</title>
		<link>http://techguyinmidtown.com/2008/05/12/remarks-on-language-dabbling-considered-wasteful/</link>
		<comments>http://techguyinmidtown.com/2008/05/12/remarks-on-language-dabbling-considered-wasteful/#comments</comments>
		<pubDate>Mon, 12 May 2008 22:11:06 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[learning]]></category>

		<guid isPermaLink="false">http://techguyinmidtown.wordpress.com/?p=15</guid>
		<description><![CDATA[Today I saw this well-written post by Michael Easter, refuting a popular (and well-written) post by Gustavo Duarte, titled &#8220;Language Dabbling Considered Wasteful.&#8221; Duarte argues that some developers overestimate the benefits of learning new computer languages. He claims that once a developer has an effective &#8220;minimal language set,&#8221; then he or she is better off [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techguyinmidtown.com&amp;blog=3566010&amp;post=15&amp;subd=techguyinmidtown&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I saw this <a href="http://codetojoy.blogspot.com/2008/05/logical-fallacies-considered-harmful.html">well-written post</a> by<span class="post-author"> Michael Easter, refuting <a href="http://duartes.org/gustavo/blog/post/language-dabbling-considered-wasteful">a popular (and well-written) post</a> by Gustavo Duarte, titled </span><span class="post-author">&#8220;Language Dabbling Considered Wasteful.&#8221;  Duarte </span><span class="post-author">argues that some developers overestimate the benefits of learning new computer languages.  He claims that once a developer has an effective &#8220;minimal language set,&#8221; then he or she is better off working to improve within that set.</span></p>
<p>I expected to disagree with Gustav because I have written production-quality software in many languages, including Ruby, Python, Perl, C, C++, C#, Java, and Erlang.  I&#8217;m currently learning Haskell in my spare time (and I&#8217;m loving it).  I think that my efforts in all of these languages has kept me nimble.  I&#8217;ve met a lot of one trick ponies who I think would benefit from the change in perspective that a new language brings.</p>
<p>Instead, I think Gustav makes several valid points.  In fact, in a subsequent prefix to his post, he writes that in the past seven years he&#8217;s added two languages to his core set, and dropped one; so he&#8217;s had fairly decent turnover.  He hasn&#8217;t been a Java horse for the past 10 years.</p>
<p>Even so, I would like to make a few quick points:</p>
<ol>
<li>The real challenge is finding an efficient and productive way to keep learning and to stay in an innovative frame of mind.  If you fall into the trap of punching the clock every day without staying aware of new approaches and techniques, then you&#8217;ll quickly fall behind.</li>
<li>Just as with exercise routines or diets, motivating forces are highly personal.  I happen to think that I learn new languages rather quickly, so my learning curve is relatively flat.  I also get a lot of pleasure and inspiration when I work in a new language, which carries over to concurrent projects in my old languages.  Those benefits are personal though &#8212; I can&#8217;t speak for others.</li>
<li>Even a developer who prefers to maintain a small proficiency set should also have a willingness to tackle new projects in a new language.  I never let a language get in the way of cooperation.  I&#8217;m certainly quick to object to uncommented code or poorly organized components, but I ultimately do not care what language is picked.  I have seen far too many people who immediately jump to the question of &#8220;what language will we use?&#8221; when the better question is &#8220;how should we solve this problem?&#8221;</li>
</ol>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/techguyinmidtown.wordpress.com/15/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/techguyinmidtown.wordpress.com/15/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techguyinmidtown.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techguyinmidtown.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techguyinmidtown.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techguyinmidtown.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techguyinmidtown.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techguyinmidtown.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techguyinmidtown.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techguyinmidtown.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techguyinmidtown.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techguyinmidtown.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techguyinmidtown.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techguyinmidtown.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techguyinmidtown.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techguyinmidtown.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techguyinmidtown.com&amp;blog=3566010&amp;post=15&amp;subd=techguyinmidtown&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techguyinmidtown.com/2008/05/12/remarks-on-language-dabbling-considered-wasteful/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92ebb01dce9310ed1f6898975c14ea23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
		<item>
		<title>I&#8217;m Learning Haskell</title>
		<link>http://techguyinmidtown.com/2008/04/27/im-learning-haskell/</link>
		<comments>http://techguyinmidtown.com/2008/04/27/im-learning-haskell/#comments</comments>
		<pubDate>Sun, 27 Apr 2008 17:38:54 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Haskell]]></category>
		<category><![CDATA[learning]]></category>

		<guid isPermaLink="false">http://techguyinmidtown.wordpress.com/?p=6</guid>
		<description><![CDATA[For the past couple of months I have been learning Haskell. I don&#8217;t have an immediate need to know the language, but I like looking at solutions through the lens of functional programming. I caught the functional bug last year when I wrote a distributed computing framework in Erlang for a large investment bank. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techguyinmidtown.com&amp;blog=3566010&amp;post=6&amp;subd=techguyinmidtown&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For the past couple of months I have been learning Haskell.  I don&#8217;t have an immediate need to know the language, but I like looking at solutions through the lens of functional programming.</p>
<p>I caught the functional bug last year when I wrote a distributed computing framework in Erlang for a large investment bank.  The distributed computing features of Erlang were certainly nice, but I also appreciated the code&#8217;s predictable execution.  If the code compiled, it almost always worked as expected.</p>
<p>Sparked by that experience, I started looking around for another functional language to learn.  Rumblings in the blogosphere about Haskell&#8217;s strict, succinct expressions caught my attention, so I started learning the language and hacking up some code.</p>
<p>Thanks to excellent documentation coupled with expert answers on the #haskell IRC channel, I feel like I&#8217;ve ramped up fairly quickly.  I intend to give a little back to the Haskell community by writing posts that attempt to clarify concepts that I found confusing.  I&#8217;m currently preparing a post that offers yet another introduction to monads.  I also want to post some code that I&#8217;ve written to allow the expression and manipulation of recurring dates.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/techguyinmidtown.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/techguyinmidtown.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/techguyinmidtown.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/techguyinmidtown.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/techguyinmidtown.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/techguyinmidtown.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/techguyinmidtown.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/techguyinmidtown.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/techguyinmidtown.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/techguyinmidtown.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/techguyinmidtown.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/techguyinmidtown.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/techguyinmidtown.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/techguyinmidtown.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/techguyinmidtown.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/techguyinmidtown.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=techguyinmidtown.com&amp;blog=3566010&amp;post=6&amp;subd=techguyinmidtown&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://techguyinmidtown.com/2008/04/27/im-learning-haskell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92ebb01dce9310ed1f6898975c14ea23?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Greg</media:title>
		</media:content>
	</item>
	</channel>
</rss>
