ДП
Size: a a a
ДП
VV
fun all_except_option (s1, sl) =
let fun comp (s1, sl) = case sl of
[] => []
| slh::slt => if same_string(s1, slh)
then slt
else slh::comp(s1,slt)
in
if comp (s1,sl) = sl
then NONE
else SOME (comp(s1,sl))
end
VV
Aß
VV
ДП
Aß
ДП
Aß
Aß
ДП
VV
While most people rely on intuition for, “which calls are tail calls,” we can be more precise by defining tail
position recursively and saying a call is a tail call if it is in tail position. The definition has one part for each
kind of expression; here are several parts:•In fun f(x) = e, e is in tail position.
•If an expression is not in tail position, then none of its subexpressions are in tail position.
•If if e1 then e2 else e3 is in tail position, then e2 and e3 are in tail position (but not e1). (Case-
expressions are similar.)
•If let b1 ... bn in e end is in tail position, then e is in tail position (but no expressions in the
bindings are).
•Function-call arguments are not in tail position.
VV
Tail recursion is common for functions that process lists, but the concept is more general. For example, here
are two implementations of the factorial function where the second one uses a tail-recursive helper function
so that it needs only a small constant amount of call-stack space:
fun fact1 n = if n=0 then 1 else n * fact1(n-1)
fun fact2 n =
let fun aux(n,acc) = if n=0 then acc else aux(n-1,acc*n)
in
aux(n,1)
end
ДП
VV
VV
ДП
end
как конец стейтментов по типу циклов и точку с запятой на конце, прям 0 смысла.ДП
ДП
VV