let range lo hi =
let rec helper res j =
if lo > j then res
else helper (j::res)(j-1)
in helper [] hi
let _ = range 0 3
(*
helper [] 3
===> helper (3::[]) 2
===> helper (2::3::[]) 1
===> helper (1::2::3::[]) 0
===> helper (0::1::2::3::[]) (-1)
===> [0;1;2;3]
*)
let rec evens xs = match xs with
| [] -> []
| x::xs' -> if (x mod 2) = 0
then x::(evens xs')
else (evens xs')
let rec fourLets xs = match xs with
| [] -> []
| x::xs' -> if String.length x = 4
then x::(fourLets xs')
else (fourLets xs')
let rec filter decider xs = match xs with
| [] -> []
| x::xs' -> if (decider x)
then x::(filter decider xs')
else (filter decider xs')
let rec listUpper xs = match xs with
| [] -> []
| x::xs' -> (String.uppercase x) :: (listUpper xs')
let evens xs = filter (fun x -> x mod 2 = 0) xs
let evens = filter (fun x -> x mod 2 = 0)
let fourLets = filter (fun x -> String.length x = 4)
(* These two are equivalent *)
(*
let foo x = bar x
let foo = bar
*)
let rec len xs = match xs with
| [] -> 0
| x::xs' -> 1 + (len xs')
let rec sum xs = match xs with
| [] -> 0
| x::xs' -> x + (sum xs')
let rec concat xs = match xs with
| [] -> ""
| x::xs' -> "..."