[m-users.] Inst problem
Mark Brown
mark at mercurylang.org
Sun Nov 2 12:19:29 AEDT 2025
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 :-)
Cheers,
Mark
>
> TIA,
> Volker
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org
> https://lists.mercurylang.org/listinfo/users
More information about the users
mailing list