[m-users.] A naming and access problem

Volker Wysk post at volker-wysk.de
Tue May 18 22:33:19 AEST 2021


Ohh, you're using an existential type and what Ralf Becket calls
"specialised insts" in his (non-finished) Mercury tutorial. I'm afraid I
can't help you with that.

What I don't understand is, why does the compiler say something about
unification with "index(Out)". This isn't there!

Bye
Volker

Am Dienstag, den 18.05.2021, 13:13 +0100 schrieb Sean Charles
(emacstheviking):
> Yes that was line 199 and arg/4 is
> 
>     % arg(Data, NonCanon, Index, Argument)
>     %
>     % Given a data item (Data) and an argument index (Index), starting
>     % at 0 for the first argument, binds Argument to that argument of
>     % the functor of the data item. If the argument index is out of range
>     % -- that is, greater than or equal to the arity of the functor or
>     % lower than 0 -- then the call fails.
>     %
>     % Note that this predicate only returns an answer when NonCanon is
>     % do_not_allow or canonicalize.  If you need the include_details_cc
>     % behaviour use deconstruct.arg_cc/3.
>     %
> :- some [ArgT] pred arg(T, noncanon_handling, int, ArgT).
> :- mode arg(in, in(do_not_allow), in, out) is semidet.
> :- mode arg(in, in(canonicalize), in, out) is semidet.
> :- mode arg(in, in(canonicalize_or_do_not_allow), in, out) is semidet.
> 
> 
> 
> 
> > On 18 May 2021, at 12:36, Volker Wysk <post at volker-wysk.de> wrote:
> > 
> > Am Dienstag, den 18.05.2021, 09:00 +0100 schrieb Sean Charles
> > (emacstheviking):
> > > Hi, I have a token definition like this:
> > > 
> > > :- type location
> > >           ---> pos(index::int, line::int, col::int).
> > > 
> > > % for ast detection later.
> > > :- type token
> > >           ---> tk(location, string)
> > >           ; '('(location) ; ')'(location)
> > >           ; '['(location) ; ']'(location)
> > >           ; '{'(location) ; '}'(location)
> > >           ; c1(location, string) ; cn(location, string)
> > >           ; s1(location, string) ; s2(location, string)
> > >           .
> > > 
> > > Given the above, I have now realised that I can’t easily (?) access the location part of any particulr instance of the token type because it doesn’t have a name and thus no field reader will be generated. As I understand it, I would have to give a unique name.
> > > 
> > > I tried:
> > > 
> > >    arg(Tok1, canonicalize, 0, Out),
> > > 
> > > and was rewarded with this message from the compiler,
> > > 
> > > repl.m:199: In clause for predicate `run_lex'/3:
> > > repl.m:199: in argument 1 of call to predicate `lexer.on_string'/4:
> > > repl.m:199: in argument 2 of functor `string.between/3’:
> > > repl.m:199: in unification of argument
> > > repl.m:199: and term `index(Out)’:
> > > repl.m:199: type error in argument of functor `index'/1.
> > > repl.m:199: Argument 1 (Out) has type `(some [ArgT] ArgT)’,
> > > repl.m:199: expected type was `lexer.location’.
> > > 
> > > Which is fair enough but how do I do it? That message is currently above my pay grade.
> > > Have I overlooked something blindingly obvious?
> > 
> > Is that "arg(Tok1, canonicalize, 0, Out)" the line 199? There isn't any term
> > "index(Out)". What's the declaration of arg/4?
> > 
> > Volker
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20210518/df6d0a35/attachment.sig>


More information about the users mailing list