[m-users.] Inst problem
Volker Wysk
post at volker-wysk.de
Sun Nov 2 21:10:58 AEDT 2025
Am Sonntag, dem 02.11.2025 um 12:19 +1100 schrieb Mark Brown:
> On Sat, Nov 1, 2025 at 9:45 PM Volker Wysk <post at volker-wysk.de> wrote:
> >
> > Hi!
> >
> > I have this:
> >
> > ------------
> > :- type iosupp.res(T)
> > ---> ok(T)
> > ; error(iosupp.error).
> >
> > :- inst iosupp.res(I)
> > ---> ok(I)
> > ; error(ground).
> >
> > :- type path ---> path(
> > abs :: bool,
> > comps :: list(string)
> > ).
> >
> > :- inst abs_path == bound(path(bound(yes), ground)).
> >
> > :- pred absolute_path_p(path, iosupp.res(path), io, io).
> > :- mode absolute_path_p(in, out(res(abs_path)), di, uo) is det.
> >
> > :- pred current_directory_p(
> > iosupp.res(path)::out(iosupp.res(abs_path)),
> > io::di, io::uo
> > ) is det.
> >
> > absolute_path_p(Path, Res, !IO) :-
> > (
> > if Path ^ abs = yes
> > then Res = iosupp.ok(Path)
> > else dirsupp.current_directory_p(Res1, !IO),
> > (
> > Res1 = ok(Cwd),
> > Res = ok(path(yes, Cwd ^ comps ++ Path ^ comps))
> > ;
> > Res1 = iosupp.error(Err),
> > Res = iosupp.error(Err)
> > )
> > ).
> > ------------
> >
> > And I get this error message from the compiler:
> >
> > iosupp.m:1065: In clause for `absolute_path_p(in,
> > out(iosupp.res(iosupp.abs_path)), di, uo)':
> > iosupp.m:1065: mode error: argument 2 had the wrong instantiatedness.
> > iosupp.m:1065: Final instantiatedness of `Res' was
> > iosupp.m:1065: unique(
> > iosupp.m:1065: error(ground)
> > iosupp.m:1065: ;
> > iosupp.m:1065: ok(
> > iosupp.m:1065: bound(
> > iosupp.m:1065: path(ground, ground)
> > iosupp.m:1065: )
> > iosupp.m:1065: )
> > iosupp.m:1065: ),
> > iosupp.m:1065: expected final instantiatedness was
> > iosupp.m:1065: named inst res(abs_path)
> > iosupp.m:1065: which expands to
> > iosupp.m:1065: bound(
> > iosupp.m:1065: error(ground)
> > iosupp.m:1065: ;
> > iosupp.m:1065: ok(
> > iosupp.m:1065: named inst abs_path
> > iosupp.m:1065: which expands to
> > iosupp.m:1065: bound(
> > iosupp.m:1065: path(
> > iosupp.m:1065: bound(
> > iosupp.m:1065: yes
> > iosupp.m:1065: ),
> > iosupp.m:1065: ground
> > iosupp.m:1065: )
> > iosupp.m:1065: )
> > iosupp.m:1065: )
> > iosupp.m:1065: ).
> >
> >
> > I think I understand the final instantiatedness of `Res', and that it
> > doesn't match the mode line for absolute_path_p. But how *should* it be
> > done?
>
> I would do this:
>
> :- type path
> ---> absolute_path(list(string))
> ; relative_path(list(string)).
>
> Or something else that better reflects what the type actually is :-)
This looks like a good idea. No more fightig with insts. But I already have
much code which uses my presend form of type "path"...
Thanks, Volker
More information about the users
mailing list