<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr</title>
<link>http://snipplr.com/language/haskell</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Tue, 14 Feb 2012 14:38:51 GMT</pubDate>
<item>
<title>(Haskell) Simultaneous filter and  map - deepsoul</title>
<link>http://snipplr.com/view/59474/simultaneous-filter-and--map/</link>
<description><![CDATA[ <p>The `filtermap` functional below allows to perform the standard `map` and `filter` operations in one go.  The mapping function has to return a `Maybe` monad, and values of  `Nothing` are filtered out.</p> ]]></description>
<pubDate>Thu, 06 Oct 2011 07:53:01 GMT</pubDate>
<guid>http://snipplr.com/view/59474/simultaneous-filter-and--map/</guid>
</item>
<item>
<title>(Haskell) Haskell 99 Problems - Problem 23 - rtperson</title>
<link>http://snipplr.com/view/58582/haskell-99-problems--problem-23/</link>
<description><![CDATA[ <p>problem 23, Extract a given number of randomly selected elements from a list. 
    Example:

    Prelude System.Random>rnd_select "abcdefgh" 3 >>= putStrLn

        "eda"
        
    Two problems: 1) How to return a list, and 2) how to sample without duplication</p> ]]></description>
<pubDate>Sat, 10 Sep 2011 07:27:49 GMT</pubDate>
<guid>http://snipplr.com/view/58582/haskell-99-problems--problem-23/</guid>
</item>
<item>
<title>(Haskell) Haskell 99 Problems, numbers 1 through 9 - rtperson</title>
<link>http://snipplr.com/view/58509/haskell-99-problems-numbers-1-through-9/</link>
<description><![CDATA[ <p>I had originally started these problems from #10 (Run-length encoding). I went back and did 1-8 for completeness.</p> ]]></description>
<pubDate>Thu, 08 Sep 2011 00:23:54 GMT</pubDate>
<guid>http://snipplr.com/view/58509/haskell-99-problems-numbers-1-through-9/</guid>
</item>
<item>
<title>(Haskell) Haskell 99 Problems - Number 20,  Arrowed! - rtperson</title>
<link>http://snipplr.com/view/58144/haskell-99-problems--number-20--arrowed/</link>
<description><![CDATA[ <p>problem 20, (*) Remove the K'th element from a list

    *Main> removeAt 1 "abcd"
        "acd"

Trivial using a pure function. A bit more challenging if you use this problem to work up your Arrow-fu.</p> ]]></description>
<pubDate>Thu, 25 Aug 2011 01:54:30 GMT</pubDate>
<guid>http://snipplr.com/view/58144/haskell-99-problems--number-20--arrowed/</guid>
</item>
<item>
<title>(Haskell) Haskell 99 Problems - Number 18 and 19 - rtperson</title>
<link>http://snipplr.com/view/58064/haskell-99-problems--number-18-and-19/</link>
<description><![CDATA[ <p>Problem 18: Extract a slice from a list.

Given two indices, i and k, the slice is the list containing the elements between the i'th and k'th element of the original list (both limits included). Start counting the elements with 1.

Example:

    *Main> slice ['a','b','c','d','e','f','g','h','i','k'] 3 7
    "cdefg
  
9 Problem 19 - Rotate a list N places to the left.

    *Main> rotate ['a','b','c','d','e','f','g','h'] 3
    "defghabc"
 
    *Main> rotate ['a','b','c','d','e','f','g','h'] (-2)
    "ghabcdef"
(This one is so easy it feels like cheating...)</p> ]]></description>
<pubDate>Sun, 21 Aug 2011 01:58:02 GMT</pubDate>
<guid>http://snipplr.com/view/58064/haskell-99-problems--number-18-and-19/</guid>
</item>
<item>
<title>(Haskell) Haskell 99 Problems - Number 17 - rtperson</title>
<link>http://snipplr.com/view/57981/haskell-99-problems--number-17/</link>
<description><![CDATA[ <p>problem 17, Split a list into two parts; the length of the first part is given. 
    Do not use any predefined predicates. (Meaning no splitAt or take or drop)
    *Main> split "abcdefghik" 3
            ("abc", "defghik")</p> ]]></description>
<pubDate>Thu, 18 Aug 2011 06:50:09 GMT</pubDate>
<guid>http://snipplr.com/view/57981/haskell-99-problems--number-17/</guid>
</item>
<item>
<title>(Haskell) Haskell 99 Problems - Numbers 15 and 16 - rtperson</title>
<link>http://snipplr.com/view/57971/haskell-99-problems--numbers-15-and-16/</link>
<description><![CDATA[ <p>problem 15, Replicate the elements of a list a given number of times. 
    > repli "abc" 3
        "aaabbbccc"

    problem 16, Drop every N'th element from a list. 
    *Main> dropEvery "abcdefghik" 3
        "abdeghk"</p> ]]></description>
<pubDate>Thu, 18 Aug 2011 03:59:30 GMT</pubDate>
<guid>http://snipplr.com/view/57971/haskell-99-problems--numbers-15-and-16/</guid>
</item>
<item>
<title>(Haskell) Haskell 99 Problems - Number 14 - rtperson</title>
<link>http://snipplr.com/view/57921/haskell-99-problems--number-14/</link>
<description><![CDATA[ <p>problem 14, Duplicate the elements of a list
    > dupli [1, 2, 3]
        [1,1,2,2,3,3]</p> ]]></description>
<pubDate>Thu, 18 Aug 2011 01:04:04 GMT</pubDate>
<guid>http://snipplr.com/view/57921/haskell-99-problems--number-14/</guid>
</item>
<item>
<title>(Haskell) Haskell 99 Problems - Solutions to 11 and 12 - rtperson</title>
<link>http://snipplr.com/view/57309/haskell-99-problems--solutions-to-11-and-12/</link>
<description><![CDATA[ <p>problem 11, modified run-length encoding
========================================
If an element has no duplicates, mark it as such. 

Example:

    encodeModified "aaaabccaadeeee"

    [Multiple 4 'a',Single 'b',Multiple 2 'c',
        Multiple 2 'a',Single 'd',Multiple 4 'e']

problem 12, Decode a run-length encoded list. 
=============================================
Given a run-length code list generated as specified in problem 11. Construct its uncompressed version. 

Example:

    decodeModified 
       [Multiple 4 'a',Single 'b',Multiple 2 'c',
        Multiple 2 'a',Single 'd',Multiple 4 'e']

    "aaaabccaadeeee"</p> ]]></description>
<pubDate>Fri, 29 Jul 2011 08:03:55 GMT</pubDate>
<guid>http://snipplr.com/view/57309/haskell-99-problems--solutions-to-11-and-12/</guid>
</item>
<item>
<title>(Haskell) Run-Length Encoding in Haskell - rtperson</title>
<link>http://snipplr.com/view/57300/runlength-encoding-in-haskell/</link>
<description><![CDATA[ <p>Problem 10 of the famous 99 Problems. I got 99 problems, but a Lisp ain't one.</p> ]]></description>
<pubDate>Fri, 29 Jul 2011 06:08:49 GMT</pubDate>
<guid>http://snipplr.com/view/57300/runlength-encoding-in-haskell/</guid>
</item>
<item>
<title>(Haskell) Towers of Hanoi by Bit Twiddling - rtperson</title>
<link>http://snipplr.com/view/56194/towers-of-hanoi-by-bit-twiddling/</link>
<description><![CDATA[ <p>Credit where it's due: I got this from udpn over at codereview.stackexchange.com. I'm just putting it here for further study.</p> ]]></description>
<pubDate>Thu, 07 Jul 2011 01:45:07 GMT</pubDate>
<guid>http://snipplr.com/view/56194/towers-of-hanoi-by-bit-twiddling/</guid>
</item>
<item>
<title>(Haskell) Towers of Hanoi in Haskell - rtperson</title>
<link>http://snipplr.com/view/56191/towers-of-hanoi-in-haskell/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Thu, 07 Jul 2011 01:05:06 GMT</pubDate>
<guid>http://snipplr.com/view/56191/towers-of-hanoi-in-haskell/</guid>
</item>
<item>
<title>(Haskell) Real World Haskell Exercise - Ch 4 - rtperson</title>
<link>http://snipplr.com/view/54660/real-world-haskell-exercise--ch-4/</link>
<description><![CDATA[ <p>The first fold exercise from RWH, Chapter 4</p> ]]></description>
<pubDate>Wed, 01 Jun 2011 01:00:47 GMT</pubDate>
<guid>http://snipplr.com/view/54660/real-world-haskell-exercise--ch-4/</guid>
</item>
<item>
<title>(Haskell) Real World Haskell Exercise - Ch 4, Ex 2-4 - rtperson</title>
<link>http://snipplr.com/view/54659/real-world-haskell-exercise--ch-4-ex-24/</link>
<description><![CDATA[ <p>I'm posting the rest of these, mostly because I'm still patting myself on the back for my point-free implementation of exercise 3, and because I give myself about two months before I entirely forget how I did it...</p> ]]></description>
<pubDate>Wed, 01 Jun 2011 00:59:27 GMT</pubDate>
<guid>http://snipplr.com/view/54659/real-world-haskell-exercise--ch-4-ex-24/</guid>
</item>
<item>
<title>(Haskell) Fibonacci List One-Liner in Haskell - rtperson</title>
<link>http://snipplr.com/view/54657/fibonacci-list-oneliner-in-haskell/</link>
<description><![CDATA[ <p>I didn't invent this, but it's too cool a snippet not to capture. Here's a one-liner that will generate a list of Fibonacci numbers in linear time.

EXPLANATION: the colon operator is used to add elements to a list, so it starts out adding on the two base cases, zero and one. After you have these two, you can mathematically generate the rest of the list. The zipWith function takes two lists and combines them using a function (in this case, addition). The two lists in question are fiblist (that is, the list you're currently generating) and "tail fiblist" (that is, every element of the list after the first element). 

The only reason this works is because Haskell's laziness gives it the ability to define infinite lists. Haskell will never even attempt to calculate the nth Fibonacci number until it is asked to do so.</p> ]]></description>
<pubDate>Wed, 01 Jun 2011 00:44:37 GMT</pubDate>
<guid>http://snipplr.com/view/54657/fibonacci-list-oneliner-in-haskell/</guid>
</item>
<item>
<title>(Haskell) Haskell Radix Conversion using ByteStrings - rtperson</title>
<link>http://snipplr.com/view/54655/haskell-radix-conversion-using-bytestrings/</link>
<description><![CDATA[ <p>Another radix conversion, when you need to zippy greatness of Haskell's ByteString.(Haskell strings are slooooow!)</p> ]]></description>
<pubDate>Wed, 01 Jun 2011 00:30:19 GMT</pubDate>
<guid>http://snipplr.com/view/54655/haskell-radix-conversion-using-bytestrings/</guid>
</item>
<item>
<title>(Haskell) Haskell Radix Conversion - rtperson</title>
<link>http://snipplr.com/view/54654/haskell-radix-conversion/</link>
<description><![CDATA[ <p>Converts an integer from base 10 to a string of base x (where 0 > x >= 20). The only thing I'd improve is getting rid of all the calls to error. Perhaps hand back a Maybe String that simply hands back Nothing if unable to convert the number.</p> ]]></description>
<pubDate>Wed, 01 Jun 2011 00:26:01 GMT</pubDate>
<guid>http://snipplr.com/view/54654/haskell-radix-conversion/</guid>
</item>
<item>
<title>(Haskell) FizzBuzz in Haskell - rtperson</title>
<link>http://snipplr.com/view/54653/fizzbuzz-in-haskell/</link>
<description><![CDATA[ <p>The dread FizzBuzz question -- really, a test if your average programmer knows his or her FOR loops. The spec is that you're counting from 1 to 100. Your program should print out "fizz" if the index is divisible by three, and "buzz" if it's divisible by five, and "fizzbuzz" if it's divisible by both.

I have a couple different versions in this code: first, a few functions just fizzing or buzzing. Second, a generalization which allows any standard message against any divisor. Third, a purely functional version that zips two lists together (giving us free concatenation for "fizzbuzz"). Fourth, a list comprehension and lastly, a monadic version that calls a pure function that uses guards.</p> ]]></description>
<pubDate>Wed, 01 Jun 2011 00:14:43 GMT</pubDate>
<guid>http://snipplr.com/view/54653/fizzbuzz-in-haskell/</guid>
</item>
<item>
<title>(Haskell) Euler Problem 4 in Haskell - rtperson</title>
<link>http://snipplr.com/view/54652/euler-problem-4-in-haskell/</link>
<description><![CDATA[ <p>A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 * 99.

Find the largest palindrome made from the product of two 3-digit numbers.

 There are shorter ways to do this, and I cheat a bit by counting down to 900 rather than 100, but this one short-circuits when it finds the answer, and so is very efficient.</p> ]]></description>
<pubDate>Wed, 01 Jun 2011 00:11:10 GMT</pubDate>
<guid>http://snipplr.com/view/54652/euler-problem-4-in-haskell/</guid>
</item>
<item>
<title>(Haskell) takeAllMVars - CopperKoo</title>
<link>http://snipplr.com/view/54619/takeallmvars/</link>
<description><![CDATA[ <p>Collecting all values in mvar boxes, assuming all mvars are filled at some point. This function does not block on every element of the MVar list, but proceeds with other elements of the list.</p> ]]></description>
<pubDate>Tue, 31 May 2011 06:18:29 GMT</pubDate>
<guid>http://snipplr.com/view/54619/takeallmvars/</guid>
</item>
</channel>
</rss>
