zoukankan      html  css  js  c++  java
  • 初识Haskell 六:IO

    对Haskell中涉及IO处理的部分进行总结


    IO在Haskell中有自己的类型,即IO(),输入和输出都是IO()

     

    IO函数

    putChar :: Char -> IO()

    putStr :: String -> IO()

    print :: Show a => a -> IO()

    getChar :: IO Char

    getLine :: IO String

    interact :: (String -> String) -> IO()

    (>>) :: IO a -> IO b ->  IO b --将2个IO操作串联,抛弃第1个IO操作的结果

    (>>=) :: IO a -> (a -> IO b) -> IO b --将2个IO操作串联,第1个IO操作的结果传到第2个

    File IO

    其中type FilePath = String

    readFile :: FilePath -> IO String

    writeFile :: FilePath -> String -> IO ()

    appendFile :: FilePath -> String -> IO () --如:

      appendFile "squares.txt" (show [(x, x*x) | x <- [1..9]])

    do notation

    对于一串IO操作,用(>>)或(>>=)过于繁琐,可写于do中,注意Haskell是layout-sensitive的。

  • 相关阅读:
    Python标准库--abc模块
    Python标准库--argparse模块
    爬虫基础
    jQuery基础
    前端基础之javascript
    web前端之HTML
    MySQL常用语句
    多线程和多进程
    socket网络编程
    异常处理
  • 原文地址:https://www.cnblogs.com/Will-zyq/p/13118303.html
Copyright © 2011-2022 走看看