Category Archives: Haskell

(Haskell) Pi Approximation

GHC already has `pi’ built in, but I wanted to compare values. `(this snippet) == pi’ returns `True’.

Posted in Haskell | Tagged , , , , , | Leave a comment

(Haskell) Euler Problem 4

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 [...]

Posted in Haskell | Tagged , , , , , | Leave a comment

(Haskell) FizzBuzz

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. [...]

Posted in Haskell | Tagged , , , , , | Leave a comment

(Haskell) Radix Conversion

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.

Posted in Haskell | Tagged , , , , , | Leave a comment

(Haskell) Fibonacci List Oneliner

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 [...]

Posted in Haskell | Tagged , , , , , | Leave a comment

(Haskell) Radix Conversion using ByteStrings

Another radix conversion, when you need to zippy greatness of Haskell’s ByteString.(Haskell strings are slooooow!)

Posted in Haskell | Tagged , , , , , | Leave a comment

(Haskell) Real World Haskell Exercise Ch 4, Ex 2-4

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…

Posted in Haskell | Tagged , , , , , | Leave a comment

(Haskell) Real World Haskell Exercise Chapter 4

The first fold exercise from RWH, Chapter 4

Posted in Haskell | Tagged , , , , , | Leave a comment

(Haskell) Towers of Hanoi

Posted in Haskell | Tagged , , , , , | Leave a comment

Fibonacci sequence in Haskell

The fibonacci sequence has many applications , such asĀ paintings , predicting stock market changes and even sunflowers. This example illustrates the fibonacci sequence in Haskell.

Posted in Haskell | Tagged , , , , , , , | Leave a comment