Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell - What makes 'main' unique?

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?

like image 386
patr1ckm Avatar asked Jun 06 '11 22:06

patr1ckm


People also ask

What makes Haskell unique?

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.

What is so great about Haskell?

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.

Why is Haskell not popular?

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.

What are the three characteristics of Haskell that make it different from ML?

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.


1 Answers

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.

like image 154
Cat Plus Plus Avatar answered Oct 21 '22 10:10

Cat Plus Plus