Commit d2d1a86b authored by Dan Grossman's avatar Dan Grossman
Browse files

add lec02 code, very slightly tweaked from au21 (removed the example of an...

add lec02 code, very slightly tweaked from au21 (removed the example of an explicit return type, which is a matter of instructor taste)
parent 87b254e9
(* These two lines will be at the top of provided lecture code
just to make the repl cleaner for teaching. You can leave
them commented out, or not, or use them in your homework,
or not, as you wish. *)
(* #utop_prompt_dummy
let _ = UTop.set_show_box false *)
let max ((x:int),(y:int)) =
if x > y then x else y
let is_even (x : int) =
(x mod 2) = 0
let average ((x:int),(y:int)) =
(x+y)/2
let average_ceil ((x:int),(y:int)) =
((x+y)/2) + (if not (is_even (x + y)) then 1 else 0)
let average_ceil_or_not ((x:int),(y:int),(ceil:bool)) =
((x+y)/2) + (if ceil && not (is_even (x + y)) then 1 else 0)
let average_f ((x:float),(y:float)) =
(x +. y) /. 2.0
(* Note: pow assumes y >= 0 *)
let rec pow ((x:int),(y:int)) =
if y = 0
then 1
else x * pow(x,y-1)
let cube (x:int) = pow(x,3)
let sixtyfour = cube 4
let fortytwo = pow(2,4) + pow(4,2) + cube 2 + 2
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment