// // Course: BU CAS CS 520 // Instructor: Hongwei Xi (hwxi AT cs DOT bu DOT edu) // (* ****** ****** *) // // How to compile: // atscc -o fact -O3 fact.dats // // How to test: // ./fact // (* ****** ****** *) // // nmul: {i,j:nat} (int i, int j): [ij:nat] int (ij) // extern fun fact {i:nat} (x: int i): [r:nat] int r // a nat is returned implement fact (x) = if x > 0 then x nmul fact (x-1) else 1 // end of [fact] (* ****** ****** *) implement main () = let val n = 3 val ans = fact (fact n) in printf ("fact (fact (%i)) = %i\n", @(n, ans)); end // end of [main] (* ****** ****** *) (* end of [fact.dats] *)