简体   繁体   English

SML:declear但不定义函数

[英]SML: declear but not define function

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. 这当然是行不通的,因为在编译reducemax函数时,你调用了一个名为最低值的未定义函数。

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? 我知道我可以使用let来声明最低的reducemax函数,但有没有办法解决这个问题? For example like in C, declare the function without defining it. 例如,在C中,声明函数而不定义它。 I do understand the reducemax function need to know lowest will return an int and taking a int * int argument. 我确实理解reducemax函数需要知道最低将返回一个int并采用一个int * int参数。

Just replace the second fun with and and remove the semicolons. 只需用and替换第二个fun ,然后删除分号。 This defines mutually recursive functions. 这定义了相互递归的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM