An implementation in Haskell

You asked for it... :smiley_cat: