fun rtfind
(f: int -> int): int = let
fun loop (
f: int -> int, n: int
) : int =
if f(n) = 0 then n else loop (f, n+1)
// end of [loop]
in
loop (f, 0)
end // end of [rtfind]
fun rtfind (f: int -> int): int = let fun loop ( n: int ) :(* <cloref1> *) int = if f(n) = 0 then n else loop (n+1)in loop (0)endHi! First time using both google groups and ATS, so forgive me if this is a really dumb question or the wrong spot but this seems like the best place to get in contact with other ATS people :p
I'm working through the intro to programming in ATS book, and in this section it says that you should denote functions which use a value not at the top level nor in the function arguments with <cloref1>.
In the next section on higher order functions, there's a function which is supposed to find the first natural number root of a given polynomial. The example given looks like this:fun rtfind
(f: int -> int): int = let
fun loop (
f: int -> int, n: int
) : int =
if f(n) = 0 then n else loop (f, n+1)
// end of [loop]
in
loop (f, 0)
end // end of [rtfind]
I was a little curious, so I removed `f` from the inner `loop` function and re-compiled, curious to see if I would get an error for having not included <cloref1>fun rtfind(f: int -> int): int = letfun loop (n: int) :(* <cloref1> *) int =if f(n) = 0 then n else loop (n+1)inloop (0)end
As it is, this works fine, but what I found more surprising was that uncommenting <cloref1> results in this:am I missing something here? I have atspre_staload.hats included in my file fwiw
Welcome!The book was written several years back.ATS has since evolved a lot. For instance, rtfind couldbe implemented as follows in ATS-Temptory:fn
rtfind
(
f: int -> int
): stream_vt(int) =
(
stream_vt_filter
(sint_streamize_gte(0))
) where
{
impltmp
stream_vt_filter$test<int>(n) = (f(n) = 0)
}Returning a stream of all the roots of a given function 'f' makes'rtfind' a lot more flexible.The "classical" ATS code tends to be like code in C or ML. Newer ATS codeemphasizes a lot more on "batch-processing". Please find some explanationand documentation in the following directory and also some coding examples: