[m-users.] Import only notations from a module?

Anders Lundstedt mercury-users at anderslundstedt.se
Sat Jul 13 21:53:14 AEST 2024


Dear all,


I like using ‘use_module’ instead of ‘import_module’ since this forces
me to properly qualify names. However, some notations would be nice to
have—in particular, list notations.


I would be fine with having to redefine notations, as for example in
the following non-compiling attempt (which does compile if one imports
the list module and removes my attempt at redefining the notations).


Code:

:- module list_notations.

:- interface.

:- use_module list.

:- func '[]'                    = list.list(T).
:- func '[|]'(T, list.list(T))  = list.list(T).

:- func replace_everything(T, list.list(T)) = list.list(T).

:- implementation.

[]        = list.'[]'.
[HD | TL] = list.'[|]'(HD, TL).

replace_everything(A, L) = RES :- (
  if L = [_ | TL] then
    RES = [A | replace_everything(A, TL)]
  else
    RES = []
).


Compilation error message:

list_notations.m:018: In clause for `replace_everything(in, in) = out':
list_notations.m:018:   in argument 1 of call to function
list_notations.m:018:   `list_notations.[|]'/2:
list_notations.m:018:   mode error: variable `V_7' has instantiatedness `free',
list_notations.m:018:   expected instantiatedness was `ground'.



Best,

Anders Lundstedt


More information about the users mailing list