nested local declarations in ML of NJ

后端 未结 1 945
野的像风
野的像风 2021-01-18 04:57

hello everyone I have this snippet of the code:

local
 helper(f, i, j) = local
                    fun NTimesF(f, n:int) = 
                    if n = 1 then         


        
相关标签:
1条回答
  • There are two ways to define local functions and variables in SML: local ... in ... end and let ... in ... end.

    The difference between local and let is that with local what comes between in and end are one or more variable or function declarations. With let what comes between in and end is an expression.

    Unlike local, let is an expression and the value of a let expression is the value of the expression between in and end.

    Since in your case you have an expression between in and end (and you want the function to evaluate to the result of that expression), you need to use let, not local.

    0 讨论(0)
提交回复
热议问题