Re: Haskell and qualified identifiers

On Wed, 2004-12-08 at 17:04 +0100, Henning Thielemann wrote:
On Wed, 8 Dec 2004, Duncan Coutts wrote:
There are actually several options here, you can import modules only qualified, then every value from that module needs to be qualified. Some modules are designed to be used this way, see for example Data.HashTable http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data.HashTable.ht... (and people are encouraged to write new modules in this style).
Good to know that there others who conform to this style. But ... why is the name of HashTable still HashTable.HashTable? Wouldn't be HashTable.T, HashTable.Type or something like that the better choice?
I see your point. I use HashTable like so: import Data.HashTable (HashTable) import qualified Data.HashTable as HashTable That way you can use HashTable unqualified as the name of the type, and then all the other operations are qualified like HashTable.new, HashTable.lookup etc This is like the C++/Java OOP naming convention. The class name is the type and it also qualifies all of the operations. This style is quite readable I find without requiring java.system.io.very.long.qualified.names.all.over.the.place. :-) Duncan

On Wed, 8 Dec 2004, Duncan Coutts wrote:
I use HashTable like so:
import Data.HashTable (HashTable) import qualified Data.HashTable as HashTable
If you give a generic name for the type, you can leave out the first 'import' and can stick completely to qualified identifiers, like HashTable.T. This makes also clear that the module name should match the data type described in the module (particularly in singular form), and that each module should handle only one (essential) data type.
participants (2)
-
Duncan Coutts
-
Henning Thielemann