stmd implementation in haskell