I feel like maybe I’ve run in to this problem before, but I’m not sure …
last_word is not getting the proper type with the if/else.
//Word size:
#define WSZ 8
#define BUFSZ 1024
//loopFILE (tail-recursive function):
//1: check if read byte cnt is 0 or size of buffer;
// if so, read in up to BUFSZ bytes
//2: if # of read bytes mod WSZ is not 0, set a check
// for last word, and test these bytes individually;
// set early stop condition for default algorithm
//3: else if # of read bytes < BUFSZ, set early stop condition
//Does it make sense to change some vars to vals?
fun loopFILE {n:nat} (nl: ulint, buf: &bytes n, n: size_t n, cnt: int
, last_word: int, rb: int, fil: &FILE r): ulint = let
// Any useful way to do dependent types with modulo?
val (rb, last_word) = (if mod_int_int(cnt, BUFSZ) = 0 then let
val [m:int] m = fread_byte (file_mode_lte_r_r | buf, n, fil)
val cnt = 0
val rb = mod_int_int(int_of_size(m),WSZ)
val m = int_of_size(m)
val _ = $showtype m
val last_word: int = (if rb > 0 then m-1 else m)
//val last_word = m*m-1 // this typechecks
val _ = $showtype last_word
in (rb, last_word) end //typecheck problem here
else (0,BUFSZ)) // end of [if]
in // in of [loopBUF]
nl + ulint_of_int(int_of_bool(hb))
end // end of [loopBUF]
SHOWTYPE(/media/RAID5/share/ATS_learning/line_count.dats: 2452(line=69,
offs=25) – 2453(line=69, offs=26)): S2Ecst(int_t0ype)
SHOWTYPE(/media/RAID5/share/ATS_learning/line_count.dats: 2589(line=72,
offs=25) – 2598(line=72, offs=34)): S2EVar(17)
warning(3): s3bexp_make_s2exp: s2e0 = S2Etyleq(0; S2Etyrec(flt; 0;
0=S2Ecst(int_t0ype), 1=S2EVar(17)), S2EVar(13))
/media/RAID5/share/ATS_learning/line_count.dats: 2606(line=73, offs=8) –
2621(line=73, offs=23): warning(3): the constraint [S2Etyleq(0;
S2Etyrec(flt; 0; 0=S2Ecst(int_t0ype), 1=S2EVar(17)), S2EVar(13))] cannot be
translated into a form accepted by the constraint solver.
/media/RAID5/share/ATS_learning/line_count.dats: 2606(line=73, offs=8) –
2621(line=73, offs=23): error(3): unsolved constraint: C3STRprop(main;
S2Etyleq(0; S2Etyrec(flt; 0; 0=S2Ecst(int_t0ype), 1=S2EVar(17)),
S2EVar(13)))
type-checking has failed: there are some unsolved constraints: please
inspect the above reported error message(s) for information.