caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] mutually dependent modules
@ 2003-02-17 14:54 Giuseppe Lo Presti
  2003-02-17 18:29 ` Chris Hecker
  0 siblings, 1 reply; 10+ messages in thread
From: Giuseppe Lo Presti @ 2003-02-17 14:54 UTC (permalink / raw)
  To: caml-list

Hi all,
Let's suppose that we have two mutually dependent modules, a.ml and
b.ml, i.e. in b.ml there is a call like A.f1() and in a.ml there is a
call like B.f2(). The question is how to link these modules? The .cmi
and .cmo compiling process runs ok, but when the linker tries to build
the executable, it stops saying something like:
Reference to undefined global `B'
make: *** [executable] Error 2
Any ideas?
Giuseppe Lo Presti


-------------------
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] mutually dependent modules
  2003-02-17 14:54 [Caml-list] mutually dependent modules Giuseppe Lo Presti
@ 2003-02-17 18:29 ` Chris Hecker
  2003-02-17 22:03   ` Issac Trotts
  0 siblings, 1 reply; 10+ messages in thread
From: Chris Hecker @ 2003-02-17 18:29 UTC (permalink / raw)
  To: Giuseppe Lo Presti, caml-list


>Let's suppose that we have two mutually dependent modules, a.ml and
>b.ml, i.e. in b.ml there is a call like A.f1() and in a.ml there is a
>call like B.f2(). The question is how to link these modules?

You can't.  Caml doesn't support circular references in modules.  Search 
the list for lots of threads and in-depth discussion on this topic.

Chris

-------------------
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] mutually dependent modules
  2003-02-17 18:29 ` Chris Hecker
@ 2003-02-17 22:03   ` Issac Trotts
  2003-02-19  4:36     ` cashin
  0 siblings, 1 reply; 10+ messages in thread
From: Issac Trotts @ 2003-02-17 22:03 UTC (permalink / raw)
  To: OCaml List

Chris Hecker wrote:

>
>> Let's suppose that we have two mutually dependent modules, a.ml and
>> b.ml, i.e. in b.ml there is a call like A.f1() and in a.ml there is a
>> call like B.f2(). The question is how to link these modules?
>
>
> You can't.  Caml doesn't support circular references in modules.  
> Search the list for lots of threads and in-depth discussion on this topic.
>
> Chris

It's easy to get the desired effect.


let print = print_endline

module A = struct
  let rec f1() = (!f2)(); print "A.f1"
  and f2 = ref(fun () -> ())
end;;

module B =
struct
  let f1 = ref(fun () -> ())
  let f2 () = print "B.f2"
  let f3 () = (!f1)()
end;;

let _ = A.f2 := B.f2
let _ = B.f1 := A.f1
let _ = A.f1()
let _ = print "--"
let _ = B.f3();;

Issac



-------------------
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] mutually dependent modules
  2003-02-17 22:03   ` Issac Trotts
@ 2003-02-19  4:36     ` cashin
  2003-02-19  5:18       ` Issac Trotts
  0 siblings, 1 reply; 10+ messages in thread
From: cashin @ 2003-02-19  4:36 UTC (permalink / raw)
  To: Issac Trotts; +Cc: OCaml List

Issac Trotts <ijtrotts@ucdavis.edu> writes:

...
> let _ = A.f2 := B.f2

I've seen this before, but why is it preferable to this?

  A.f2 := B.f2

There's an article on comp.lang.ml where Xavier Leroy mentions this
syntax as a way to get module initialization code to run ... but I get
the impression that folks are using it when it's semantically
equivalent to the same thing with the "let _ = " omitted entirely.

-- 
--Ed L Cashin            |   PGP public key:
  ecashin@uga.edu        |   http://noserose.net/e/pgp/

-------------------
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] mutually dependent modules
  2003-02-19  4:36     ` cashin
@ 2003-02-19  5:18       ` Issac Trotts
  2003-02-19  9:04         ` Michal Moskal
  2003-02-20 19:19         ` Christophe TROESTLER
  0 siblings, 2 replies; 10+ messages in thread
From: Issac Trotts @ 2003-02-19  5:18 UTC (permalink / raw)
  To: cashin; +Cc: OCaml List

cashin@cs.uga.edu wrote:

>Issac Trotts <ijtrotts@ucdavis.edu> writes:
>
>...
>  
>
>>let _ = A.f2 := B.f2
>>    
>>
>
>I've seen this before, but why is it preferable to this?
>
>  A.f2 := B.f2
>
>
>There's an article on comp.lang.ml where Xavier Leroy mentions this
>syntax as a way to get module initialization code to run ... but I get
>the impression that folks are using it when it's semantically
>equivalent to the same thing with the "let _ = " omitted entirely.
>
I've seen both, but I now avoid the "let _ = " expression because if you 
leave it
out then ocamlc gives a warning when you don't supply all the arguments 
to a
function.  The warning is good to have.

Issac



-------------------
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] mutually dependent modules
  2003-02-19  5:18       ` Issac Trotts
@ 2003-02-19  9:04         ` Michal Moskal
  2003-02-20 19:19         ` Christophe TROESTLER
  1 sibling, 0 replies; 10+ messages in thread
From: Michal Moskal @ 2003-02-19  9:04 UTC (permalink / raw)
  To: Issac Trotts; +Cc: cashin, OCaml List

On Tue, Feb 18, 2003 at 09:18:49PM -0800, Issac Trotts wrote:
> I've seen both, but I now avoid the "let _ = " expression because if you 
> leave it
> out then ocamlc gives a warning when you don't supply all the arguments 
> to a
> function.  The warning is good to have.

let () = f a b c in
let () = g c in
let () = a := b in
...

but after writing lots of imperative code (using camlgl), I found
regular:

f a b c;
g c;
a := b;
...

clearer.

All you need is to remember priority of ';' WRT if-then, match and so
on.

-- 
: Michal Moskal ::::: malekith/at/pld-linux.org :  GCS {C,UL}++++$ a? !tv
: PLD Linux ::::::: Wroclaw University, CS Dept :  {E-,w}-- {b++,e}>+++ h

-------------------
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] mutually dependent modules
  2003-02-19  5:18       ` Issac Trotts
  2003-02-19  9:04         ` Michal Moskal
@ 2003-02-20 19:19         ` Christophe TROESTLER
  2003-02-20 21:18           ` Issac Trotts
  2003-02-21 14:50           ` cashin
  1 sibling, 2 replies; 10+ messages in thread
From: Christophe TROESTLER @ 2003-02-20 19:19 UTC (permalink / raw)
  To: ijtrotts; +Cc: caml-list

On Tue, 18 Feb 2003, Issac Trotts <ijtrotts@ucdavis.edu> wrote:
> 
> I've seen both, but I now avoid the "let _ = " expression because if
> you leave it out then ocamlc gives a warning when you don't supply
> all the arguments to a function.  The warning is good to have.

Use
	let () = ...
-------------------
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] mutually dependent modules
  2003-02-20 19:19         ` Christophe TROESTLER
@ 2003-02-20 21:18           ` Issac Trotts
       [not found]             ` <20030221.191628.125299099.debian00@tiscali.be>
  2003-02-21 14:50           ` cashin
  1 sibling, 1 reply; 10+ messages in thread
From: Issac Trotts @ 2003-02-20 21:18 UTC (permalink / raw)
  To: caml-list

Christophe TROESTLER wrote:

>On Tue, 18 Feb 2003, Issac Trotts <ijtrotts@ucdavis.edu> wrote:
>  
>
>>I've seen both, but I now avoid the "let _ = " expression because if
>>you leave it out then ocamlc gives a warning when you don't supply
>>all the arguments to a function.  The warning is good to have.
>>    
>>
>
>Use
>	let () = ...
>
I only know of one place where that would be needed:

 class foo () =
    let () = frobnicate() in
    object
        ...  
    end

since

 class foo () =
    frobnicate();
    object
        ...  
    end

doesn't work.  Otherwise, what's the point?

Issac

   

-------------------
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] mutually dependent modules
  2003-02-20 19:19         ` Christophe TROESTLER
  2003-02-20 21:18           ` Issac Trotts
@ 2003-02-21 14:50           ` cashin
  1 sibling, 0 replies; 10+ messages in thread
From: cashin @ 2003-02-21 14:50 UTC (permalink / raw)
  To: Christophe TROESTLER; +Cc: ijtrotts, caml-list

Christophe TROESTLER <debian00@tiscali.be> writes:

> On Tue, 18 Feb 2003, Issac Trotts <ijtrotts@ucdavis.edu> wrote:
>> 
>> I've seen both, but I now avoid the "let _ = " expression because if
>> you leave it out then ocamlc gives a warning when you don't supply
>> all the arguments to a function.  The warning is good to have.
>
> Use
> 	let () = ...

Thanks for the advice.  Why is that a good idea?  Right now, it seems
like the let idiom is only helpful in a few specific instances.

-- 
--Ed L Cashin            |   PGP public key:
  ecashin@uga.edu        |   http://noserose.net/e/pgp/

-------------------
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Caml-list] mutually dependent modules
       [not found]             ` <20030221.191628.125299099.debian00@tiscali.be>
@ 2003-02-22  4:38               ` Issac Trotts
  0 siblings, 0 replies; 10+ messages in thread
From: Issac Trotts @ 2003-02-22  4:38 UTC (permalink / raw)
  To: OCaml List

Christophe TROESTLER wrote:

>On Thu, 20 Feb 2003, Issac Trotts <ijtrotts@ucdavis.edu> wrote:
>  
>
>>Christophe TROESTLER wrote:
>>    
>>
>>>	let () = ...
>>>      
>>>
>>I only know of one place where that would be needed: [...]
>>    
>>
>
>What about the simple example:
>----------------------------------------------------------------------
>print_int
>let f x = x + 1
>----------------------------------------------------------------------
>
>Compiling this gives no warning (like what you mention for let _ =
>print_int).  On the other hand, if one had written
>----------------------------------------------------------------------
>let () = print_int
>let f x = x + 1
>----------------------------------------------------------------------
>
>Please correct me if I misunderstood the intent of your mail.
>
>Cheers,
>ChriS
>
Sure, you're right in this case, but I don't tend to write code that way.
In files it would tend to be something like

let foo() =
        print_int;
        let f x = x + 1 in
        f 3;;
File "foo.ml", line 2, characters 8-17:
Warning: this function application is partial,
maybe some arguments are missing.

On the command line I would break it up with ;;'s:

# print_int;;                                 
- : int -> unit = <fun>
# let f x = x + 1 in f 3;;
- : int = 4

Issac





-------------------
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-02-22  4:33 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-17 14:54 [Caml-list] mutually dependent modules Giuseppe Lo Presti
2003-02-17 18:29 ` Chris Hecker
2003-02-17 22:03   ` Issac Trotts
2003-02-19  4:36     ` cashin
2003-02-19  5:18       ` Issac Trotts
2003-02-19  9:04         ` Michal Moskal
2003-02-20 19:19         ` Christophe TROESTLER
2003-02-20 21:18           ` Issac Trotts
     [not found]             ` <20030221.191628.125299099.debian00@tiscali.be>
2003-02-22  4:38               ` Issac Trotts
2003-02-21 14:50           ` cashin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).