caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Undefined recursive module
@ 2014-09-10 20:32 Yotam Barnoy
  2014-09-10 22:20 ` Jeremy Yallop
  0 siblings, 1 reply; 7+ messages in thread
From: Yotam Barnoy @ 2014-09-10 20:32 UTC (permalink / raw)
  To: Ocaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 102 bytes --]

I just encountered this nasty RUNTIME error in my code. What does it mean?
How does it happen?

Yotam

[-- Attachment #2: Type: text/html, Size: 147 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread
* [Caml-list] Undefined_recursive_module
@ 2004-07-27  1:23 Hawkins, Thomas
  2004-07-27  7:22 ` Alain Frisch
  0 siblings, 1 reply; 7+ messages in thread
From: Hawkins, Thomas @ 2004-07-27  1:23 UTC (permalink / raw)
  To: caml-list

I just started experimenting with recursive modules, but have hit a snag with Undefined_recursive_module.

Basically I need to define an ADT where the data structure contains Sets and the Set elements reference back to the data structure.  In the following example, the mutually recursive modules include the main data structure (Process), an ordered type (Files), and a set (FileSet returned from the Set functor).

Both the Process and the File modules define only function values, therefore I believe the example satisfies the "safe module" requirement.  It does compile and run for one case (see does_work).  However, if I make multiple calls to Process.add_file, Undefined_recursive_module is raised (see does_not_work).

Any suggestions?  (I'm using 3.08.0)

Thanks,

Tom






module rec Process :
  sig
    type t
    val create    : unit -> t
    val add_file  : File.t -> t -> unit 
    val print     : t -> unit
  end
  =
  struct
    type t = { mutable files : FileSet.t }
    
    let create () =
      { files = FileSet.empty }

    let add_file file process =
      process.files <- FileSet.add file process.files

    let print process =
      FileSet.iter File.print process.files
  end

and File :
  sig
    type t
    val compare   : t -> t -> int
    val create    : Process.t -> string -> t
    val print     : t -> unit
  end
  =
  struct
    type t = Process.t * string

    let compare a b =
      match a, b with (_, a), (_, b) -> String.compare a b

    let create process name =
      process, name

    let print (_, name) =
      print_string name;
      print_newline ()
  end

and FileSet :
  Set.S with type elt = File.t
  =
  Set.Make(File)
;;



let does_work () =
  let p = Process.create () in
  Process.add_file (File.create p "file1") p;
  Process.print p
;;


let does_not_work () =
  let p = Process.create () in
  Process.add_file (File.create p "file1") p;
  Process.add_file (File.create p "file2") p;
  Process.print p
;;


(*
does_work ();;
*)
does_not_work ();;

-------------------
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] 7+ messages in thread

end of thread, other threads:[~2014-09-10 23:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-10 20:32 [Caml-list] Undefined recursive module Yotam Barnoy
2014-09-10 22:20 ` Jeremy Yallop
2014-09-10 22:26   ` Yotam Barnoy
2014-09-10 22:50     ` Jeremy Yallop
2014-09-10 23:16       ` Yotam Barnoy
  -- strict thread matches above, loose matches on Subject: below --
2004-07-27  1:23 [Caml-list] Undefined_recursive_module Hawkins, Thomas
2004-07-27  7:22 ` Alain Frisch

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