~npalix/coccinelle/upstream

« back to all changes in this revision

Viewing changes to commons/interfaces.ml

  • Committer: Nicolas Palix
  • Date: 2010-01-28 14:23:49 UTC
  • Revision ID: git-v1:70d17887795852eca805bfe27745b9810c0a39be
Remove trailing whitespace/tab

svn path=/coccinelle/; revision=8684

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
(*****************************************************************************)
6
6
(*
7
7
 * Use this not so much for functors, I hate functors, but
8
 
 * more to force me to have consistent naming of stuff. 
9
 
 * 
 
8
 * more to force me to have consistent naming of stuff.
 
9
 *
10
10
 * It's related to objet.ml in some way, but use a different scheme.
11
 
 * 
12
 
 * src: (strongly) inspired by Jane Street core lib, which in turn 
 
11
 *
 
12
 * src: (strongly) inspired by Jane Street core lib, which in turn
13
13
 * may have been strongly inspired by Java Interfaces or Haskell
14
14
 * TypeClass.
15
 
 * 
16
 
 * 
17
 
 * 
 
15
 *
 
16
 *
 
17
 *
18
18
 * Example of use in .mli:
19
 
 * 
 
19
 *
20
20
 *   open Interfaces
21
21
 *   include Stringable with type stringable = t
22
22
 *   include Comparable with type comparable = t
23
 
 * 
 
23
 *
24
24
 * Example of use in .ml:
25
 
 * 
 
25
 *
26
26
 *   type xxx
27
27
 *   type stringable = xxx
28
28
 *   let of_string = bool_of_string
29
29
 *   let to_string = string_of_bool
30
 
 * 
31
 
 * 
 
30
 *
 
31
 *
32
32
 * No this file is not about (graphical) user interface. See gui.ml for that.
33
 
 * 
34
 
 * 
35
 
 * todo? but as in type class, or object, can not have default method 
 
33
 *
 
34
 *
 
35
 * todo? but as in type class, or object, can not have default method
36
36
 * with this scheme ?
37
37
 *)
38
38
 
45
45
(* note: less need for cloneable, copyable as in Java. Only needed
46
46
 * when use ref, but refs should be avoided anyway so better not to
47
47
 * encourage it.
48
 
 * 
 
48
 *
49
49
 * Often found this in haskell:
50
 
 * 
 
50
 *
51
51
 *    data x = ... deriving (Read, Show, Eq, Ord, Enum, Bounded)
52
 
 * 
 
52
 *
53
53
 * Apparently this is what is considered basic by haskell.
54
54
 *)
55
55
 
72
72
 
73
73
 
74
74
 
75
 
(* Same, should not use compare normally, dangerous when evolve code. 
 
75
(* Same, should not use compare normally, dangerous when evolve code.
76
76
 * Called Ord in haskell. Inherit Eq normally.
77
77
 *)
78
78
module type Compare_able = sig
82
82
(* Jane street have also some binable, sexpable *)
83
83
 
84
84
 
85
 
(* Haskell have lots of related type class after Num such as 
 
85
(* Haskell have lots of related type class after Num such as
86
86
 * Real, Fractional, Integral, RealFrac, Floating, RealFloat
87
87
 *)
88
88
module type Num_able = sig
167
167
 
168
168
(*****************************************************************************)
169
169
(* Idea taken from Jane Street Core library, slightly changed.
170
 
 *   
171
 
 * It's another way to organize data structures, module instead of objects. 
172
 
 * It's also the Java way. 
173
 
 * 
 
170
 *
 
171
 * It's another way to organize data structures, module instead of objects.
 
172
 * It's also the Java way.
 
173
 *
174
174
 * It makes some code looks a little bit like Haskell* typeclass.
175
 
 * 
 
175
 *
176
176
 *)
177
177
 
178
178
(* In Jane Street they put each interface in its own file but then have to
179
179
 * do that:
180
 
 * 
 
180
 *
181
181
 * module type Stringable = Stringable.S
182
182
 * module type Comparable = Comparable.S
183
183
 * module type Floatable = Floatable.S
188
188
 * module type Setable = Setable.S
189
189
 * module type Sexpable = Sexpable.S
190
190
 * module type Binable = Binable.S
191
 
 * 
 
191
 *
192
192
 * And I dont like having too much files, especially as all those xxable
193
193
 * end with able, not start, so don't see them together in the directory.
194
194
 *)