let sum_triple ((x:int),(y:int),(z:int)):int =
x + y + z
let sum_triple (x, y, z) =
x + y + z
let empty lst =
match lst with
[] -> true
| h::t -> false
let rec sum_list (lst : int list) : int =
match lst with
[] -> 0
| h::t -> h + sum_list(t)
let rec length (lst : int list) : int =
match lst with
[] -> 0
| x::xs -> 1 + length(xs)
let rec append ((lst1:'a list),(lst2:'a list))
: 'a list =
match lst1 with
[] -> lst2
| h::t -> h::append(t,lst2)
(* append is available as built-in operator @ *)
let max (x, y) =
if x>y then x else y
let rec max_list (lst : int list) : int option =
match lst with
[] -> None
| h::t -> match max_list(t) with
None -> Some h
| Some x -> Some (max(h,x))
type mytype = TwoInts of int * int
| Str of string
| Pizza
let f (x:mytype) : int =
match x with
Pizza -> 3
| TwoInts(i1,i2) -> i1+i2
| Str s -> String.length s
type suit = Club | Diamond | Heart | Spade
type rank = Jack | Queen | King
| Ace | Num of int
(* Every student either has an id number
* or (temporarily) is identified by name. *)
type student_id =
IdNum of int
| FullName of string