Skip to content

Commit

Permalink
Add syntax check fn q
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-byrne committed Oct 29, 2024
1 parent 9fbd3d3 commit f1de05e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/exam01/question5.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
fun q4 _ ([], []) = true
| q4 _ ([], x::xs) = false
| q4 _ (x::xs, []) = false
| q4 f (x::xs,y::ys) = y = (f x) andalso q4 f (xs, ys);


(* Question 4a
My answer: true
Correct answer: error, because cannot do equality check on reals
*)
(* q4 (fn x => x + 1.0) ([1.1,2.2,3.3], [2.1,3.2,4.3]); *)

(* Question 4b
My answer: true
Correct answer: error, because the operand should be a tuple of
two lists and this is currying with 2 arguments.
I.e., should be q4 floor ([1.1,2.2,3.3], [1,2,3])
*)
(* q4 floor [1.1,2.2,3.3] [1,2,3]; *)

(* Question 4c
My answer: false
Correct answer: false, because of simple arithmetic reasons
*)
q4 (fn x => x*x) ([1,2,3],[1,4,9,16]);

(* Question 4d
My answer: Error because tries to perform an equality operation between int list and int but equality operator requires two arguments of the same type.
Correct answer: true
*)
q4 (hd) ([[1,2], [2,3,4], [3,4,5,6,7]],[1,2,3]);

0 comments on commit f1de05e

Please sign in to comment.