Skip to content

Instantly share code, notes, and snippets.

@vaskaloidis
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaskaloidis/10015816 to your computer and use it in GitHub Desktop.
Save vaskaloidis/10015816 to your computer and use it in GitHub Desktop.
Standard ML functions to: raise a number to a given power, find the smallest of 3 numbers and cycle the first element of a list to thelast
(* Raises a to the power of b *)
fun pow(a:real, b:int) :real =
if b > 1 then a * pow(a, (b - 1))
else a;
(* Raises a to the power of b but it is a real*real->real *)
fun power((a, b):(real*real)) =
if a <= 0.0 then 1.0
else a * pow(a, b - 1.0):real;
(* Finds the smallest of 3 numbers *)
fun min3(a:int, b:int, c:int) :int =
if a < b then
if a < c then a
else if c < b then c
else b
else if b < c then
if b < a then b
else if c < a then c
else a
else if c < a then
if c < b then c
else if b < a then b
else a
else 0;
(* Cycles the first element of a list to the end *)
fun cycle (a) =
tl a @ [hd a];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment