Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let rec sumList aList =
- match aList with
- | [] -> 0
- | head :: tail -> head + sumList tail
- let minList aL =
- let h = List.head aL
- let rec min aList cur =
- match aList with
- | [] -> 0
- | head :: [] -> if head < cur then head else cur
- | head :: tail -> if head < cur then min tail head else min tail cur
- min aL h
- let maxList aL =
- let h = List.head aL
- let rec max aList cur =
- match aList with
- | [] -> 0
- | head :: [] -> if head > cur then head else cur
- | head :: tail -> if head > cur then max tail head else max tail cur
- max aL h
- let search aL elem =
- let rec searchList aList =
- match aList with
- | [] -> false
- | head :: [] -> if head = elem then true else false
- | head :: tail -> if head = elem then true else searchList tail
- searchList aL
- let firstHalf aList =
- let rec dropLast = function
- | ([] | [_]), _ -> []
- | x, ([] | [_]) -> []
- | x::xt, y::ys::yt -> x :: dropLast (xt, yt)
- dropLast (aList, aList)
- let x = firstHalf [0;1;2;3;4;5;6;7]
- let a = [1;2;3;4;45;6;7;8;9;0;100]
- let x = sumList a // 185
- let y = minList a // 0
- let z = maxList a // 100
- let mu = search a 100 // True
- let x = firstHalf [0;1;2;3;4;5;6;7] // [0; 1; 2; 3]
Add Comment
Please, Sign In to add comment