Dear Experts,
I'm a sort of newbe so be patient with if I ask something too silly
(I've googled around but I didn't find anything really usefull).

At the moment I'm investigating on how the OCaML module system and the
separate compilation works.

Nothing original I took the priority queue example from the user manual
and split it into three files (attached): one with the structure (A.ml)
one with the signature (A.mli) and one with a silly main (main.ml).

Following the instructions in the manual I have tried to compile each
file without linking but the only that compiles with success is the file
with the signature since it doesn't refer to any other file.

When I compile the structure or the main I get this error:
  >ocamlc -c A.ml
  File "A.ml", line 17, characters 39-52:
  Error: Unbound module type CharPQueueAbs

I have tried to put #use or #load in the A.ml and main.ml file but the
only result is to get a syntax error (e.g., with #use "A.mli" at the
beggining of A.ml)

  >ocamlc -c A.ml
  File "A.ml", line 1, characters 0-1:
  Error: Syntax error

What am I doing wrong? Any help is appreciate, thanks.

Walter

--
--
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

module type CharPQueueAbs =
   sig
     type priority = int         (* still concrete *)
     type char_queue            (* now abstract *)
     val empty : char_queue
     val insert : char_queue -> int -> char -> char_queue
     exception QueueIsEmpty
   end;;
#use "A.mli"

module PrioQueue =
   struct
     type priority = int
     type char_queue = Empty | Node of priority * char * char_queue * char_queue
     exception QueueIsEmpty
     
     let empty = Empty
     let rec insert queue prio elt =
       match queue with
         Empty -> Node(prio, elt, Empty, Empty)
       | Node(p, e, left, right) ->
           if prio <= p
           then Node(prio, elt, insert right p e, left)
           else Node(p, e, insert right prio elt, left)
   end;;

module AbstractPrioQueue = (PrioQueue: CharPQueueAbs);;
open AbstractPrioQueue;;

let x = insert empty 1 'a' ;;

Reply via email to