-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cuihtlauac ALVARADO
committed
Jan 17, 2024
1 parent
5089f82
commit b2b2e69
Showing
5 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
### Docs | ||
|
||
```shell | ||
# dune build @docs | ||
|
||
# open _build/default/_doc/_html/index.html | ||
``` | ||
|
||
### Tests | ||
|
||
``` | ||
# dune test | ||
``` | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
(library (name camellito) (public_name camellito)) | ||
(library (name camellito) (wrapped false) (public_name camellito) (modules task)) | ||
|
||
(test (name test) (libraries camellito ounit2) (modules test)) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
let ignore _ = () | ||
|
||
let map f u = | ||
let rec loop acc = function | ||
| [] -> acc | ||
| x :: u -> loop (f x :: acc) u in | ||
List.rev (loop [] u) | ||
|
||
let range lo = | ||
let rec loop u i = if i < lo then u else loop (i :: u) (i - 1) in loop [] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(** Module [Tasks] contains the functions that need to be implemented. | ||
The file [task.mli] contains the signature and description of the functions. | ||
It should not be modiled. | ||
Write your functions in the file [task.ml]. Replace the dummy content | ||
[failwith "Not yet implemented"] by your code. | ||
The [[@warning "-27"]] pragma can be removed once a function is implemented. | ||
*) | ||
|
||
val ignore : 'a -> unit | ||
(** Discards the value of its argument and returns the unit value [()]. For | ||
instance, [ignore (f x)] discards the result of the function [f]. Side effects | ||
triggered by the evaluation of the argument are unchanged. *) | ||
|
||
val map : ('a -> 'b) -> 'a list -> 'b list | ||
(** [map f [a1; ...; an]] applies function [f] to [[a1, ..., an]], and builds | ||
the list [[f a1; ...; f an]] with the results returned by [f]. | ||
*) | ||
|
||
val range : int -> int -> int list | ||
(** [range lo hi] returns a list of integers [[lo; lo + 1; ...; hi]]. It | ||
returns an empty list if [hi < lo]. This function is tail-recursive. *) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
open OUnit2 | ||
|
||
let sq x = x * x | ||
|
||
let ignore = [ | ||
"unit" >:: (fun _ -> assert_equal () (Task.ignore ())); | ||
"42" >:: (fun _ -> assert_equal () (Task.ignore 42)); | ||
"apply" >:: (fun _ -> assert_equal () (Task.ignore (sq 3))); | ||
"print" >:: (fun _ -> assert_equal () (Task.ignore (print_newline ()))); | ||
] | ||
|
||
let map = [ | ||
"nil" >:: (fun _ -> assert_equal [] (Task.map sq [])); | ||
"sq" >:: (fun _ -> assert_equal [1; 4; 9] (Task.map sq [1; 2; 3])); | ||
"id" >:: (fun _ -> assert_equal [1; 2; 3] (Task.map Fun.id [1; 2; 3])); | ||
"then" >:: (fun _ -> assert_equal ([1; 2; 3] |> Task.map (( + ) 1) |> Task.map sq) (Task.map (fun x -> x |> ( + ) 1 |> sq) [1; 2; 3])); | ||
] | ||
|
||
let range = [ | ||
"nil" >:: (fun _ -> assert_equal [] (Task.range 7 3)); | ||
"cons" >:: (fun _ -> assert_equal [3; 4; 5] (Task.range 3 5)); | ||
] | ||
|
||
let () = "Task" >::: [ | ||
"ignore" >::: ignore; | ||
"map" >::: map; | ||
"range" >::: range | ||
] |> run_test_tt_main |