-
Notifications
You must be signed in to change notification settings - Fork 1
/
task.ml
66 lines (52 loc) · 3.13 KB
/
task.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(** 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 modified.
Write your code in this file. Replace the dummy content [failwith "Not yet
implemented"] by your code.
The [[@warning "-27"]] pragma can be removed once a function is implemented.
{b Tips}:
1. Code samples from the tutorials can be executed in the provided environment.
Find the terminal tab, launch [utop] command. In the tutorials, copy
expressions after [#], including the [;;]. In Terminal-Utop, paste the
expression and press [Return]. The output in the Utop should be the same as
in the tutorial. You can also enter your expressions, try [2 + 2] for
instance (always finish your input by [;;] and [Return]). Exit [utop] with
[Ctrl+D] or [#quit;;]
2. You may have to delete more than the pragma and the [failwith].
3. To implement the functions `split_words` and `split_lines` you can the module
{{:https://v2.ocaml.org/releases/5.1/api/Str.html}[Str]} with the following
regular expressions: ["\r?\n"] and ["\\(\\(\r?\n\\)\\| \\|\t\\)+"]
4. To implement the function `discuss_wc` you need to use the function
{{:https://ocaml.org/p/curly/latest/doc/Curly/index.html#val-get}[Curly.get]}
from package {{:https://github.com/rgrinberg/curly}curly}. If you are using
Codespace, you'll need to install it using Opam. If you are using Replit,
it's already installed.
*)
(** TASK 1 - 4 test cases *)
let [@warning "-27"] ignore x = failwith "Not yet implemented"
(** Discards the value passed as 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. *)
(** TASK 2 - 4 test cases *)
let [@warning "-27"] map f u = failwith "Not yet implemented"
(** [map f [a1; ...; an]] applies function [f] to [[a1, ..., an]], and builds
the list [[f a1; ...; f an]] with the results returned by [f]. *)
(** TASK 3 - 2 test cases *)
let [@warning "-27"] span lo hi = failwith "Not yet implemented"
(** [span lo hi] returns a list of integers [[lo; lo + 1; ...; hi]]. It
returns an empty list if [hi < lo]. *)
(** TASK 4 - 11 test cases *)
let [@warning "-27"] split_lines u = failwith "Not yet implemented"
(** [split_lines s] returns a list of strings where each string is line in
the string [s]. Lines are delimited either by carriage return (CR, 0x0d)
followed by line feed (LF, 0x0a) or line feed alone. *)
(** TASK 5 - 21 test cases *)
let [@warning "-27"] split_words u = failwith "Not yet implemented"
(** [split_words s] returns a list of strings where each string is a word in
[s]. Words are separated by any group of carriage return (CR, 0x0d), line
feed (LF, 0x0a), space or tab characters. *)
(** TASK 6 - 0 test cases *)
let [@warning "-27"] discuss_wc id = failwith "Not yet implemented"
(** [discuss_wc id] fetches the thread [id] from https://dicuss.ocaml.org/ and
returns its line, word and character counts. The thread is queried as raw
markdown from url https://dicuss.ocaml.org/raw/id. *)