With this code:
main :: FilePath -> FilePath -> IO ()
main wrPath rdPath = do x <- readFile rdPath
writeFile wrPath x
I got the following error:
Couldn't match expected type 'IO t0'
with actual type 'FilePath -> FilePath -> IO()
But the file compiles correctly when I change the name of 'main' to something else.
What's so unique about main and why does its type have to be IO t0
?
Haskell is different in two ways: Values are immutable by default, and mutability must be explicitly indicated with a variable type. Mutating a mutable variable is considered a side effect, and that mutable is tracked by the type system.
Strong static typing, purity, and immutable data, are essential for writing code that adheres to specifications. Software written in Haskell tends to be secure, reliable, and bug-free.
Haskell is not considered as a go-to programming language for obvious reasons: its powers and elegances differ from the requirements of most popular programming. Although it's a long way off in Haskell, runtime polymorphism is one of the most used patterns in modern programming.
ML syntax is heavier, but probably more readable, particularly for larger bodies of code. Consider the differences between ML and Haskell in three broad categories: - superficial syntactic differences, - fancy extra syntax on Haskell's part, and - deep semantic differences with far-reaching implications.
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 valuemain
. The value of the program is the value of the identifiermain
in moduleMain
, which must be a computation of typeIO t
for some typet
(see Chapter 7). When the program is executed, the computationmain
is performed, and its result (of typet
) is discarded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With