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
let rec inner xs ys = | |
match xs, ys with | |
| [], [] -> 0 | |
| [], ys -> 0 | |
| xs, [] -> 0 | |
| x::xs, y::ys -> x * y + inner xs ys;; | |
(* | |
The head of the first list (xs) gets multiplied | |
by the head of the second list (ys). | |
We add the next call to this value and recursion |
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
type Exp = | |
| Num of int //number of integers | |
| Neg of Exp //negation | |
| Sum of Exp * Exp //sum | |
| Diff of Exp * Exp //difference | |
| Prod of Exp * Exp //product | |
| Quot of Exp * Exp;; //quotient | |
let rec evaluate = function | |
| Num n -> Some n |
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
let rec split = function | |
| [] -> ([], []) | |
| [a] -> ([a], []) | |
| a::b::cs -> let (M,N) = split cs in (a::M, b::N) | |
let rec merge = function | |
| ([], ys) -> ys | |
| (xs, []) -> xs | |
| (x::xs, y::ys) -> if x < y then x :: merge (xs, y::ys) | |
else y :: merge (x::xs, ys) |
OlderNewer