Advertisement
Guest User

Call/CC implementation of function map and filter

a guest
May 9th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.45 KB | None | 0 0
  1. module CallCC =
  2.  
  3.     let rec private mapk k mapper = function
  4.     | [] -> k []
  5.     | h :: t ->
  6.         mapk (fun x -> k((mapper h) :: x)) mapper t
  7.  
  8.     let map = mapk id
  9.  
  10.     let rec private filterk k predicate = function
  11.     | [] -> k []
  12.     | h :: t -> t |> filterk (fun x -> k (if (predicate h) then h :: x else x)) predicate
  13.  
  14.     let filter = filterk id
  15.  
  16. [1..10000] |> CallCC.map (fun x -> x * x) |> CallCC.filter (fun x -> (x % 2) = 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement