Haskell - What makes 'main' unique?

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

    As in C, Java, or C#, main is a special identifier in certain contexts that indicates where the program should start.

    In Haskell, main is defined to have the type IO a. You should either give your function a different name, or if you really want it to be the starting point, change its signature and have it read the arguments from the command line with getArgs

    Although you didn't ask it specifically, main is also special in that it is the only function in a Haskell program that can (safely) invoke IO actions. The Haskell runtime treats main as special.

提交回复
热议问题