Haskell Cheat Sheet Page 7

ADVERTISEMENT

Of course, this prevents our module from pattern-
Instance Declarations
It must be noted that
Exports
If an export list is not provided, then all
matching on the values of type
. We can
declarations cannot be excluded from im-
functions, types, constructors, etc. will be available
import one or more constructors explicitly:
port: all
declarations in a module will be
to anyone importing the module. Note that any im-
imported when the module is imported.
ported modules are not exported in this case. Limit-
ing the names exported is accomplished by adding
a parenthesized list of names before the
key-
All constructors for a given type can also be im-
Qualified Imports
The names exported by a
word:
ported:
module (i.e., functions, types, operators, etc.) can
have a prefix attached through qualified imports.
This is particularly useful for modules which have
a large number of functions having the same name
We can also import types and classes defined in the
as
functions.
is a good example:
module:
The same syntax as used for importing can be used
here to specify which functions, types, construc-
This form requires any function, type, constructor
In the case of classes, we can import the functions
tors, and classes are exported, with a few differ-
or other name exported by
to now be pre-
defined for a class using syntax similar to import-
ences. If a module imports another module, it can
fixed with the alias (i.e.,
) given. Here is one way
ing constructors for data types:
also export that module:
to remove all duplicates from a list:
Note that, unlike data types, all class functions are
imported unless explicitly excluded. To only import
A second form does not create an alias. Instead,
the class, we use this syntax:
the prefix becomes the module name. We can write
a simple function to check if a string is all upper
case:
A module can even re-export itself, which can be
useful when all local definitions and a given im-
Exclusions
If most, but not all, names are to be
ported module are to be exported. Below we export
imported from a module, it would be tedious to
ourselves and
, but not
:
list them all. For that reason, imports can also be
specified via the
keyword:
Except for the prefix specified, qualified imports
support the same syntax as normal imports. The
Except for instance declarations, any type, function,
name imported can be limited in the same ways as
constructor or class can be hidden.
described above.
c 2009 Justin Bailey.
7

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education