(*********************************************)
(* Laboratory Definitions required for Lab 5 *)
(* Either 'cut and paste' this file into     *)
(*  ML interactive session, or put this file *)
(*  in your ML folder/directory and load     *)
(*  using the command:                       *)
(*     use "labdefs";  or  use "labdefs.ml"; *)
(*                                           *)
(* With PolyML, load these definitions and   *)
(*  then use the command:                    *)
(*                        PolyML.commit();   *)
(*   to save them for future sessions        *)
(*********************************************)

fun maxi(n,m):int = if n > m then n else m;

fun mini(n,m):int = if n < m then n else m;

fun maxr(n,m):real = if n > m then n else m;

fun minr(n,m):real = if n < m then n else m;

(* list processing  *)

exception first_has_nil_argument;
exception rest_has_nil_argument;
exception SelectError; (* for function Select *)

fun first (nil) = raise first_has_nil_argument
  | first (head :: rest) = head;

fun rest (nil) = raise rest_has_nil_argument
  | rest (_ :: rest_list) = rest_list;

fun append (list, item) = list @ (item :: []);