Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain Haskell empty import list ()

Tags:

haskell

I saw much lines like import HSP.ServerPartT() - list of imports is empty. Why is this done? What difference with just not importing this module?

like image 353
demi Avatar asked Feb 02 '12 12:02

demi


2 Answers

It imports only typeclass instances from the module. With -Wall, GHC issues a warning for modules that are imported but from which no definitions are used:

foo.hs:1:1:
    Warning: The import of `M' is redundant
               except perhaps to import instances from `M'
             To import instances alone, use: import M()

The empty import list silences this warning and serves as documentation of the purpose of the import.

like image 134
ehird Avatar answered Oct 20 '22 04:10

ehird


That form imports nothing but the instances from that module. And that's the reason of that form, you want to have the instances in scope, but nothing else.

like image 38
Daniel Fischer Avatar answered Oct 20 '22 06:10

Daniel Fischer