Duck typing in Haskell

This is a simple Literate Haskell file demonstrating duck typing in Haskell. You copy the whole web page and paste it into a .hs file and compile/load it. Grab the normal Haskell version here.

I’m using a library called Has which you can grab from Hackage (or just cabal install has). It’s pretty neat, it allows you to define field names and their types, that you are going to use at some point, and then lets you construct/access/update arbitrary records based on those fields.

We need to enable type families and flexible class contexts to work with this library. And also it’s nice if we disable the monomorphism restriction. I don’t want mono, I want manymorphism! As many as you can fit in your pocket.