2024-11-23 20:36 AEDT

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000316mercuryBugpublic2014-02-05 18:33
Reporterlpimmes 
Assigned Tojuliensf 
PriorityhighSeveritymajorReproducibilityalways
StatusresolvedResolutionno change required 
PlatformOSOSx 10.9.1OS Version
Product Version 
Target VersionFixed in Version 
Summary0000316: Declared `det', inferred `semidet'. --- [H|T] first argument input
DescriptionThis function compiles, except for det error.
In this case, I really need det, not semidet, otherwise callers including main will not work.

:- pred charToStrLst(list(char), list(string), list(string)).
:- mode charToStrLst(in, in, out) is det.
charToStrLst([H | T], Accum, LstStr) :- % [H|T] can fail
    (if list.is_empty([H|T])
    then
    LstStr = Accum
    else
    format("%c", [c(H)], Str),
     charToStrLst(T, [Str | Accum], LstStr)
    ).

All I needed to accomplish is convert, e.g., "foo" to ["f", "o", "o"].

longCommSubseq.m:097: In `charToStrLst'(in, in, out):
longCommSubseq.m:097: error: determinism declaration not satisfied.
longCommSubseq.m:097: Declared `det', inferred `semidet'.
longCommSubseq.m:098: In argument 1 of clause head:
longCommSubseq.m:098: unification of `HeadVar__1' and `list.[H | T]' can
longCommSubseq.m:098: fail.
% Program contains determinism error(s).
Steps To Reproduce mmc --make --fully-strict -E -v -O 0 --use-subdirs longCommSubseq
Additional InformationSee attached file.
Thanks.
TagsNo tags attached.
Attached Files

-Relationships
+Relationships

-Notes

~0000639

juliensf (administrator)

The predicate charToStrLst/3 does not have a clause that matches the case where the first
argument is the empty list, which it would need in order to be det.

One way of making the above predicate det is:

charToStrLst([], Accum, Accum).
charToStrLst([H | T], Accum, LastStr) :-
     Str = string.from_char(H),
     charToStrLst(T, [Str | Accum], LastStr)

(Aside: you can use string.from_char/1 to convert characters into strings;
there's no need to use format/3).

Alternatively, you the above predicate could be written as the following function:

    :- func charToStrLst(list(char)) = list(string).

    charToStrLst(Chars) = list.map(string.from_char, Chars).

In short, the error reported by the compiler here is correct and there isn't a bug.
+Notes

-Issue History
Date Modified Username Field Change
2014-02-05 18:11 lpimmes New Issue
2014-02-05 18:11 lpimmes File Added: longCommSubseq.m
2014-02-05 18:32 juliensf Note Added: 0000639
2014-02-05 18:33 juliensf Status new => resolved
2014-02-05 18:33 juliensf Resolution open => no change required
2014-02-05 18:33 juliensf Assigned To => juliensf
+Issue History