drkcore

2010/02/10 19:10:30

Hakellでテンポラリディレクトリやテンポラリファイル

テンポラリファイルをエディタでいじって、保存するとテンポラリファイルの内容を読んでHsSyckでパースして出力する

import System.IO
import System.Process
import System.Directory
import System.Environment
import Control.Monad (liftM)
import Data.Yaml.Syck

main :: IO ()
main = do
  tmpdir <- getTemporaryDirectory
  (pathOfTempFile, h) <- openTempFile tmpdir "temp.yaml"
  editor   <- liftM (lookup "EDITOR") getEnvironment
  case editor of Just ed -> (>>= waitForProcess) . runCommand $ ed ++ " " ++ pathOfTempFile
                 Nothing -> error "command error\n"
  hClose h

  inpStr <- readFile pathOfTempFile
  yamlstr <- parseYaml inpStr
  print yamlstr

  removeFile pathOfTempFile
  return ()

HoogleGHCの標準ライブラリドキュメントが手放せない身体になってきた。

ProductName Real World Haskell―実戦で学ぶ関数型言語プログラミング
Bryan O'Sullivan,John Goerzen,Don Stewart
オライリージャパン / ¥ 3,990 ()
在庫あり。

もっとHaskellの本出ないかなぁ。Principles of Biomedical InformaticsのHaskell阪みたいなのとか。

ProductName Principles of Biomedical Informatics
Ira J. Kalet PhD
Academic Press / ¥ 7,667 ()
通常1~3週間以内に発送

Comments