This is just an example. These two functions are connected. You really want to call the one called lowest. It should then return the lowest number of the two. This of course won't work because you at the time of compiling the reducemax function you make a call to an at the time undefined function called lowest.

fun reducemax (i:int * int):int =
    if (#1 i) > (#2 i)
    then lowest(((#1 i)-1), (#2 i))
    else lowest((#1 i), ((#2 i)-1));

fun lowest (i:int * int):int =
    if (#1 i) = (#2 i)
    then (#1 i)
    else reducemax((#1 i), (#2 i));

I know I can use let to declare the reducemax function inside lowest, but is there any way around this? For example like in C, declare the function without defining it. I do understand the reducemax function need to know lowest will return an int and taking a int * int argument.

有帮助吗?

解决方案

Just replace the second fun with and and remove the semicolons. This defines mutually recursive functions.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top