Haskell - What makes 'main' unique?

后端 未结 4 1473
逝去的感伤
逝去的感伤 2021-01-12 16:03

With this code:

main :: FilePath -> FilePath -> IO ()
main wrPath rdPath = do x <- readFile rdPath
                        writeFile wrPath x
         


        
4条回答
  •  我在风中等你
    2021-01-12 16:32

    Because the language spec says so.

    A Haskell program is a collection of modules, one of which, by convention, must be called Main and must export the value main. The value of the program is the value of the identifier main in module Main, which must be a computation of type IO t for some type t (see Chapter 7). When the program is executed, the computation main is performed, and its result (of type t) is discarded.

提交回复
热议问题