Search code examples
functional-programmingsmlsmlnjml

SML Ml Programing Function is_older date with boolean conditon


I am newbie in ML programming, I have a homework to write a function is_older that takes two dates and evaluates to true or false. It evaluates to true if the first argument is a date that comes before the second argument.
(If the two dates are the same, the result is false.)

val is_older = fn : (int * int * int) * (int * int * int) -> bool // Binding Like

I tried this (using SML of New Jersy cmd prompt)

fun is_older((y1,m1,d1),(y2,m2,d2))= if (y1<y2) then true 
else if (y1=y2 andalso m1<m2) then true 
else if (y1=y2 andalso m1=m2 andalso d1<d2) then true;

Its gives error

Error syntax error: deleting SEMICOLON ID 

Solution

  • Your last if does not have an else - that's a syntax error in SML.