This file contains hidden or 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 mem a s = | |
match (a,s) with | |
| (_,[]) -> false | |
| (b,x::xs) -> if b = x then true else mem b xs |
This file contains hidden or 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 max_list = function | |
| [] -> 0 | |
| x::xs -> let max = max_list xs in if x >= max then x else max |
This file contains hidden or 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 take lst n = | |
match (lst,n) with | |
| ([],_) -> [] | |
| (x::xs,m) -> if m <= 0 then [] else x::(take xs) (m-1) | |
let rec drop lst n = | |
match (lst,n) with | |
| ([],_) -> [] | |
| (x::xs,m) -> if m > 1 then take xs (m-1) else xs |
This file contains hidden or 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 filter p = function | |
| [] -> [] | |
| x::xs -> if p x then x::filter p xs else filter p xs |
This file contains hidden or 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 unzip = function | |
| [] -> ([],[]) | |
| (x,y)::xs -> (x::fst (unzip xs),y::snd (unzip xs)) |
This file contains hidden or 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 zip lst1 lst2 = | |
match (lst1,lst2) with | |
| ([],_) | (_,[]) -> [] | |
| ((x::xs),(y::ys)) -> (x,y)::zip xs ys |
This file contains hidden or 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 concat = function | |
| [] -> [] | |
| []::xs -> concat xs | |
| (x::ls)::xs -> x :: concat (ls::xs) |
This file contains hidden or 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 nested_length = function | |
| [] -> 0 | |
| []::xs -> nested_length xs | |
| (x::ls)::xs -> 1 + nested_length (ls::xs) |
This file contains hidden or 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 romanmap = [(1000,"M");(900,"CM");(500,"D");(400,"CD");(100,"C");(90,"XC");(50,"L");(40,"XL");(10,"X");(9,"IX");(5,"V");(4,"IV");(1,"I")] | |
let rec roman romanmap n = | |
match romanmap with | |
| [] -> "" | |
| x::xs -> if fst x <= n then snd x ^ roman romanmap (n - fst x) else roman xs n |
This file contains hidden or 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 downto1 = function | |
| n -> if n < 1 then [] else n::downto1 (n-1) |