Last active
August 29, 2015 13:58
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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