Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] My wishlist: DRY modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Hurt <bhurt@s...>
Subject: [Caml-list] My wishlist: DRY modules

I'm doing some work with modules, and I'm learning some of their 
annoyances.  Number one is having to repeat module type definitions.  For 
example, say you have a file foo.  In foo.mli, you have:

module type T = sig
	type s
	val needed : ...
end

module type S = sig
	type t
	val doit : ...
	val orelse : ...
end

module Make(Arg: T) : S with type t = Arg.s

So far, so good, but now in foo.ml you need to replicate the definitions 
of *both* T and S:

module type T = sig
	type s
	val needed : ...
end

module type S = sig
	type t
	val doit : ...
	val orelse : ...
end

module Make(Arg: T) = struct
    type t = Arg.s
    let doit = ...
    let orelse = ...
end

Now, if you know your module signatures when you start, this isn't that
big of a problem- it's a cut and paste.  Unfortunately, if you don't know
your module signatures at the begining, to add or subtract or change a
type or val you need to update the signature in *three* different places.

I wish you didn't have to repeat the module definitions in the module 
file *if* you have a .mli file.

The subject line, BTW, comes from the Pragmatic Programmer book's DRY 
principle- Don't Repeat Yourself.

-- 
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
                                - Gene Spafford 
Brian

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners