Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 5207629b authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Another update in the slides of week 5.

parent c35c710e
No related branches found
No related tags found
No related merge requests found
(* GADT *)
type (_, _) closure = type (_, _) closure =
| NEqZero : (int, bool) closure | NEqZero : (int, bool) closure
| Increment : (int, int) closure | Increment : (int, int) closure
(* GADT *)
(* APPLY *)
let rec apply = let rec apply =
fun (type a b) (this : (a, b) closure) (that : a) : b -> fun (type a b) (this : (a, b) closure) (that : a) : b ->
match this with match this with
...@@ -11,23 +14,25 @@ let rec apply = ...@@ -11,23 +14,25 @@ let rec apply =
| Increment -> | Increment ->
let x = that in let x = that in
x + 1 x + 1
(* APPLY *)
(* FILTERMAP *)
let rec filter p xs = let rec filter p xs =
match xs with match xs with
| [] -> | [] -> []
[] | x :: xs -> if apply p x then x :: filter p xs
| x :: xs -> else filter p xs
if apply p x then x :: filter p xs else filter p xs
let rec map f xs = let rec map f xs =
match xs with match xs with
| [] -> | [] -> []
[] | x :: xs -> apply f x :: map f xs
| x :: xs -> (* FILTERMAP *)
apply f x :: map f xs
(* FOO *)
let foo (xs : int list) : int list = let foo (xs : int list) : int list =
filter NEqZero (map Increment xs) filter NEqZero (map Increment xs)
(* FOO *)
let () = let () =
assert (foo [ -1; 0; +1 ] = [ 1; 2 ]); assert (foo [ -1; 0; +1 ] = [ 1; 2 ]);
......
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment