Rewrite thread scheduler by Haskell