SML Ml Programmable is_older date function with boolean condition

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

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

      

I tried this (using SML from New Jersy command line cmd)

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;

      

It gives error

Error syntax error: deleting SEMICOLON ID 

      

+3


source to share


2 answers


In your last one if

there else

is no - syntax errors in SML.



+5


source


fun is_older((y1 : int,m1 : int,d1 : int),(y2 : int, m2 : int, d2 : int))=
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 
      else false;

      



+2


source







All Articles