Skip to content

An implementation of the map function in F Sharp

Here is how map may be implemented in F Sharp. (At the very least, it is my attempt at implementing it!)

You can run this in the interactive shell.

#light;;
 
let rec my_map fn xs =
    match xs with
    | first::rest -> (fn first) :: (my_map fn rest)
    | [] -> []
;;
 
my_map (fun x -> x + 1) [1; 2; 3; 4; 5;];;

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*