implements MDP pattern in Haskell