Implements MDP pattern in Haskell