Created
December 13, 2011 09:23
-
-
Save rsimoes/1471368 to your computer and use it in GitHub Desktop.
unicode string-length measuring in ATS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun string_length {n:nat} | |
(str: string n): size_t n = let | |
fun loop {i:nat | i <= n} | |
(str: string n, i: size_t i): size_t (n) = | |
if string_isnot_at_end (str, i) then loop (str, i+1) else i | |
in | |
loop (str, 0) | |
end | |
implement main () = begin | |
print( string_length("foo") ); | |
print( string_length("bar") ); | |
print( string_length("€") ); | |
print_newline(); | |
end | |
(* | |
rsimoes@desktop:~/scratch/ats$ atscc uni_stringlen.dats | |
/usr/lib/ats-anairiats-0.2.5/bin/atsopt --output uni_stringlen_dats.c --dynamic uni_stringlen.dats | |
gcc -I/usr/lib/ats-anairiats-0.2.5/ -I/usr/lib/ats-anairiats-0.2.5/ccomp/runtime/ -L/usr/lib/ats-anairiats-0.2.5/ccomp/lib64/ /usr/lib/ats-anairiats-0.2.5/ccomp/runtime/ats_prelude.c uni_stringlen_dats.c -lats | |
rsimoes@desktop:~/scratch/ats$ ./a.out | |
333 | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment