Posts Tagged ‘haskell’

Mixins vs. typeclasses

Sunday, November 22nd, 2009

This is a fragment of a discussion on polymorphism that I had in another context. I was pleased by how well this explanation came out, and wanted to put it in a more public format.

I’ve thought more about the issue you raised of whether Haskell’s typeclasses are the same as Ruby’s mixins, and I think my answer is a firm “sort of”. A Ruby mixin provides a consistent API and a consistent implementation to any class it’s added to. A Haskell typeclass provides a consistent API and an individual implementation to any type it’s defined for. It’s roughly the difference between base classes and interfaces in C++/C#/Java.

Dream it, then cause it

Monday, August 17th, 2009

One of the most fun aspects of technology is the ability to just up and create something. I actually find this easiest with stringcrafts. Feeling awkward at a party? Crochet finger puppets. Microphone for the read-aloud hard to keep at a standard distance from people’s mouths? Ply and braid a cord for it. Stuff needs transporting from hither to yon? Angle bungee cords properly to keep it from sliding off the bike rack.

I haven’t found ways to make programming usage as casual as string usage. Because of this, I sometimes forget that programming can be a casual solution to ideas or problems.

I read Simon Peyton Jones’ STM essay in Beautiful Code last night, and worked through the code to make sure I understood. I’d used STM in Haskell before, but for thorny networking problems that made it hard to understand how simple the magic actually is. At some point this morning I decided to combine STM and gtk2hs (which I’ve never used beyond a single ten-line example, and which I had installed incorrectly on my box as part of an installation of leksah) to produce a graphical representation of the Dining Philosophers problem. I now (after time off for reading, lunch, goofing off, and spending time with friends and their kittens) have a working and attractive implementation.

Creation is fun.

Project Euler

Monday, June 15th, 2009

I’ve known about Project Euler for a while, but I made the mistake of trying to use it as a vehicle to learn F#. Last week I started solving the problems with Haskell, which is vastly more fun. I highly recommend this method of recreation.

Also, this is officially the best-ever method of Fibonacci-number computation: fibs = 0 : 1 : (zipWith (\a b -> a + b) fibs $ tail fibs)