[SOLVED] CS let rec map f xs = match xs with

$25

File Name: CS_let_rec_map_f_xs_=_match_xs_with.zip
File Size: 329.7 KB

5/5 - (1 vote)

let rec map f xs = match xs with
| [] -> []
| x :: xt -> (f x)::(map f xt)

let rec fold f a xs = match xs with
| [] -> a
| x :: xt -> fold f (f a x) xt

let rec fold_right f xs a = match xs with
| [] -> a
| x :: xt -> f x (fold_right f xt a)

let length xs = fold (fun a _ -> succ a) 0 xs

let rev xs = fold (fun a x -> x :: a) [] xs

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS let rec map f xs = match xs with
$25