OCaml mode
(* A Hundred Lines of Caml - http://caml.inria.fr/about/taste.en.html *)1
(* Summing a list of integers *)2
let rec sum xs =3
match xs with4
| [] -> 05
| x :: xs' -> x + sum xs'6
7
(* Quicksort *)8
let rec qsort = function9
| [] -> []10
| pivot :: rest ->11
let is_less x = x < pivot in12
let left, right = List.partition is_less rest in13
qsort left @ [pivot] @ qsort right14
15
(* Fibonacci Sequence *)16
let rec fib_aux n a b =17
match n with18
| 0 -> a19
| _ -> fib_aux (n - 1) (a + b) a20
let fib n = fib_aux n 0 121
22
(* Birthday paradox *)23
let year_size = 365.24
25
let rec birthday_paradox prob people =26
let prob' = (year_size -. float people) /. year_size *. prob in27
if prob' < 0.5 then28
Printf.printf "answer = %d\n" (people+1)29
else30
birthday_paradox prob' (people+1) ;;31
32
birthday_paradox 1.0 1F# mode
23
1
module CodeMirror.FSharp2
3
let rec fib = function4
| 0 -> 05
| 1 -> 16
| n -> fib (n - 1) + fib (n - 2)7
8
type Point =9
{10
x : int11
y : int12
}13
14
type Color =15
| Red16
| Green17
| Blue18
19
[0 .. 10]20
|> List.map ((+) 2)21
|> List.fold (fun x y -> x + y) 022
|> printf "%i"23
MIME types defined: text/x-ocaml (OCaml) and text/x-fsharp (F#).
