View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
---|---|---|---|---|---|---|---|---|---|
0000316 | mercury | Bug | public | 2014-02-05 18:11 | 2014-02-05 18:33 | ||||
Reporter | lpimmes | ||||||||
Assigned To | juliensf | ||||||||
Priority | high | Severity | major | Reproducibility | always | ||||
Status | resolved | Resolution | no change required | ||||||
Platform | OS | OSx 10.9.1 | OS Version | ||||||
Product Version | |||||||||
Target Version | Fixed in Version | ||||||||
Summary | 0000316: Declared `det', inferred `semidet'. --- [H|T] first argument input | ||||||||
Description | This 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 Information | See attached file. Thanks. | ||||||||
Tags | No tags attached. | ||||||||
Attached Files |
|
Notes | |
juliensf (administrator) 2014-02-05 18:32 |
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. |
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 |