2014年1月1日水曜日

開発環境

C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、谷口 功 (翻訳)、オライリー・ジャパン)のⅢ部(高度なプログラミング概念)の20章(移植性の問題)、20.6(ファイル名問題)、設問20-2.をHaskellで解いてみる。

その他参考書籍

設問20-2.

コード(BBEdit)

Sample.hs

{-# OPTIONS -Wall -Werror #-}
module Main where

import System.IO
import System.FilePath
import System.Directory

main :: IO ()
main = do
    b <- findFile[d] name
    if b == Nothing then do
        hPutStrLn stderr (path ++ ": file not found")
        return ()
    else
        return ()
        
path :: FilePath
path = d ++ pathSeparator:name

d :: FilePath
d = pathSeparator:joinPath ["root", "new"]

name :: String
name = "table"

入出力結果(Terminal, runghc)

$ runghc Sample.hs
/root/new/table: file not found
$

慣れるまでは{-# OPTIONS -Wall -Werror #-}の記述を消さずに細かく型を指定していくことに。

0 コメント:

コメントを投稿