SHOW:
|
|
- or go back to the newest paste.
1 | - | ========== .ml file ========== |
1 | + | Only one line is different (the second one), and one can deal with several kind of parameters, while the other can't : |
2 | ||
3 | - | let printf brick_verb verb message = |
3 | + | ----------------------- Works : |
4 | - | Printf.ksprintf |
4 | + | let string_d = |
5 | - | (fun s -> |
5 | + | let t = 3.1 in |
6 | - | if brick_verb >= verb |
6 | + | (fun brick_name brick_verb verb x -> |
7 | - | then Printf.printf "%s" s else ()) |
7 | + | Printf.ksprintf (fun s -> |
8 | - | message |
8 | + | if verb <= brick_verb |
9 | then Printf.printf "[%s]%s" brick_name s else ()) x) | |
10 | - | ========== .mli file ========== |
10 | + | ;; |
11 | - | val printf : int -> int -> (unit, unit, string, unit) format4 -> unit |
11 | + | |
12 | ||
13 | - | ========== another .ml file ========== |
13 | + | ----------------------- Doesn't works : |
14 | - | MyModule.printf 5 2 "Hello %s !" "myname" |
14 | + | let string_d = |
15 | let t = Sys.time () in | |
16 | - | ==> Error : |
16 | + | (fun brick_name brick_verb verb x -> |
17 | - | This function has type |
17 | + | Printf.ksprintf (fun s -> |
18 | - | int -> int -> (unit, unit, string, unit) format4 -> unit |
18 | + | if verb <= brick_verb |
19 | - | It is applied to too many arguments; maybe you forgot a `;'. |
19 | + | then Printf.printf "[%s]%s" brick_name s else ()) x) |
20 | ;; | |
21 | ||
22 | ||
23 | ||
24 | ----------------------- PROF : | |
25 | ||
26 | ||
27 | ||
28 | let string_d = | |
29 | let t = 3.1 in | |
30 | (fun brick_name brick_verb verb x -> | |
31 | Printf.ksprintf (fun s -> | |
32 | if verb <= brick_verb | |
33 | then Printf.printf "[%s]%s" brick_name s else ()) x) | |
34 | ;; | |
35 | Characters 23-24: | |
36 | let t = 3.1 in | |
37 | ^ | |
38 | Warning 26: unused variable t. | |
39 | val string_d : string -> 'a -> 'a -> ('b, unit, string, unit) format4 -> 'b = | |
40 | <fun> | |
41 | # string_d "brickname" 5 1 "bonjour %s" "hi";; | |
42 | [brickname]bonjour hi- : unit = () | |
43 | # string_d "brickname" 5 1 "bonjour %d" 4;; | |
44 | [brickname]bonjour 4- : unit = () | |
45 | # let string_d = | |
46 | let t = Sys.time () in | |
47 | (fun brick_name brick_verb verb x -> | |
48 | Printf.ksprintf (fun s -> | |
49 | if verb <= brick_verb | |
50 | then Printf.printf "[%s]%s" brick_name s else ()) x) | |
51 | ;; | |
52 | Characters 23-24: | |
53 | let t = Sys.time () in | |
54 | ^ | |
55 | Warning 26: unused variable t. | |
56 | val string_d : | |
57 | string -> '_a -> '_a -> ('_b, unit, string, unit) format4 -> '_b = <fun> | |
58 | # string_d "brickname" 5 1 "bonjour %s" "hi";; | |
59 | [brickname]bonjour hi- : unit = () | |
60 | # string_d "brickname" 5 1 "bonjour %d" 4;; | |
61 | Characters 25-37: | |
62 | string_d "brickname" 5 1 "bonjour %d" 4;; | |
63 | ^^^^^^^^^^^^ | |
64 | Error: This expression has type | |
65 | (string -> unit, string -> unit) CamlinternalFormatBasics.precision | |
66 | but an expression was expected of type | |
67 | (string -> unit, int -> 'a) CamlinternalFormatBasics.precision | |
68 | Type string is not compatible with type int | |
69 | # |