write it by haskell (according Jonathan Tang's tutorial)