我正在学习编程语言课程,学习标准ML。
在第一次作业中,我尝试编写一个函数
所以我编写了以下代码:
在第一次作业中,我尝试编写一个函数
is_older
,它接受两个日期并评估为true
或false
。如果第一个参数是早于第二个参数的日期,则评估为true
(如果两个日期相同,则结果为false
)。所以我编写了以下代码:
fun is_older(first: int * int * int, second: int * int * int) =
if(#1 first = #1 second andalso #2 first = #2 second andalso #3 first = #3 second) then false
else if (#1 first < #1 second) then true
else if (#1 first = #1 second andalso #2 first < #2 second) then true
else if (#1 first = #1 second andalso #2 first = #2 second andalso #3 first < #3 second) then true
else false
这段代码运行良好,但外观很丑。
我该如何使用函数式风格重写此代码?