haskellでカレントディレクトリを表示する
Prelude> :m +System.Directory Prelude System.Directory> setCurrentDirectory "/etc" "/etc" Prelude System.Directory> putStrLn getCurrentDirectory <interactive>:1:9: Couldn't match expected type `String' against inferred type `IO FilePath' In the first argument of `putStrLn', namely `getCurrentDirectory' In the expression: putStrLn getCurrentDirectory In the definition of `it': it = putStrLn getCurrentDirectory Prelude System.Directory> do {arg<-getCurrentDirectory; putStrLn arg} /etc Prelude System.Directory> getCurrentDirectory>>=(\arg -> putStrLn arg) /etc Prelude System.Directory> getCurrentDirectory >>= putStrLn /etc Prelude System.Directory> putStrLn =<< getCurrentDirectory /etc
これってさ IOモナドの >>= の定義が IOの中身を次の関数に入れるって定義だからかな?
>>= :: IO a -> (a -> IO b) -> IO b
なるほどなぁ。