[mercury-users] Continuing confusion
Fergus Henderson
fjh at cs.mu.OZ.AU
Sat Mar 28 04:12:23 AEDT 1998
On 27-Mar-1998, Peter Phelan <peter.phelan at anite.systems.lu> wrote:
> I am trying to make a simple read-write program, at first just to read
> some term and reproduce it, and then to read some term, try various
> preds from exsiting Prolog code, and write the result.
There's an example of a program like this in samples/expand_term.m.
> I have referred to the user guide, language reference, transition guide,
> and sample programs, still can't manage it. Maybe I have missed
> something obvious, but this seems to me a weird and complicated way to
> do i/o (yes, I understand why it has to be declarative).
Judging from your questions below, it looks like your confusion doesn't
have much to do with I/O, but more to do with the basic syntax of Mercury.
> Still, I cannot understand the meaning of types such as:
>
> list(char)::in
>
> and particularly the operator
>
> ::
`list(char)::in' is not a type; it is a pair consisting of a
type (`list(char)') and a mode (`in').
The `::' operator is a "mode qualifier", and the right-hand
operand of `::' is always a mode.
The relevant part of the language reference manual is this bit
(from the "Modes" chapter):
| If a predicate or function has only one mode, the `pred' and `mode'
| declaration can be combined:
|
| :- func length(list(T)::in) = (int::out).
| :- pred append(list(T)::in, list(T)::in, list(T)::out).
The declarations given in the above example are equivalent to
:- func length(list(T)) = int.
:- mode length(in) = out.
:- pred append(list(T), list(T), list(T)).
:- mode append(in, in, out).
> I am also unable to find any reference to the type:
>
> list:list(character)
The `:' operator is a module-qualifier (as it is in many Prolog systems).
The module-qualified name `foo:bar' refers to the entity `bar'
that is defined in module `foo'.
The relevant part of the Mercury language reference manual is this bit
(from the "Modules" chapter):
| The names of predicates, functions, constructors, types, modes and
| insts can be explicitly module qualified using the `:' operator, i.e.
| `module:name'. This is useful both for readability and for resolving
| name conflicts. Uses of entities imported using `use_module'
| declarations *must* be explicitly module qualified.
|
| Currently we also support `__' as an alternative module qualifier,
| so you can write `module__name' instead of `module:name'. We are
| considering changing the module qualifier from `:' to `.' in a future
| version, so that we can use `:' as a type qualifier instead. Hence for
| the time being we recommend that you use `__' rather than `:' as module
| qualifier.
When the compiler reports errors, it typically uses the
fully module-qualified names, just in case there is any
ambiguity.
So `list:list(character)' just means "`list(character)', where
the `list' type here is the list type defined in the module list.m,
as opposed to the `list' type defined in any other modules".
As discussed previously, `character' is just another name for `char'.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the users
mailing list