Drkcore

10 02 2010 Haskell Tweet

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 ()

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

ProductName Real World Haskell―実戦で学ぶ関数型言語プログラミング
Bryan O'Sullivan
オライリージャパン / 3990円 ( 2009-10-26 )


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

ProductName Principles of Biomedical Informatics
Ira J. Kalet PhD
Academic Press / 8335円 ( 2008-10-15 )


About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021