Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it mandatory to specify the module name at start of source file?

GHC insist that the module name has to equal the file name. But if they are the same, then why does a Haskell compiler need both? Seems redundant for me. Is this only a language design mistake?

Beside the inconvinience it also raises the problem that if I want to use 2 libraries that accidentially have the same top module name, then I can not disambiguate simply by renaming the folder of one of them. What is the idiomatic solution to this problem?

like image 353
libeako Avatar asked Aug 23 '14 14:08

libeako


1 Answers

The Haskell language specification doesn't talk about files. It only talks about modules and their syntax. So there's clearly no language design mistake.

The GHC compiler (and many others) chose to follow a pattern of one module per file, and searching for modules in files with matching names. Seems like a decent strategy to me. Otherwise you'd need to provide the compiler with some mapping from module name to file name or an explicit list of every file in use.

like image 168
Carl Avatar answered Oct 30 '22 03:10

Carl