Haskell - What makes 'main' unique?

后端 未结 4 1442
逝去的感伤
逝去的感伤 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:56

    As GolezTrol said, all programs need to know which symbol to start executing when the function is invoked. Many scripting languages don't require (or just don't need) a main routine as they can have statements placed on the top level. This is not the case for Haskell, C and many others - these languages need a starting location and by convention that is the main function (as per the Haskell spec - see Cat's answer).

    Notice Haskell's main does not accept any parameters that correspond to the program arguments - these are obtained via System.Environment.getArgs.

提交回复
热议问题