caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Queue example
@ 2003-07-15  8:18 ronniec95
  2003-07-15  8:28 ` Pierre Weis
  0 siblings, 1 reply; 2+ messages in thread
From: ronniec95 @ 2003-07-15  8:18 UTC (permalink / raw)
  To: caml-list

Hi,

I'm just trying to figure out how to create a queue of a specific type in
a .ml file. I can do it in the interpreter as:

>let q = Queue.create()
>Queue.add 1 q

This creates an int queue.

Declaring this in a .ml file gives

The type of this expression, '_a Queue.t,
contains type variables that cannot be generalized


I know you can construct a Queue and put an item in it straight away to
specify the type, but I want an empty queue to start with; eg like std::queue<int>
from c++.

Any help appreciated.

Thanks.

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

* Re: [Caml-list] Queue example
  2003-07-15  8:18 [Caml-list] Queue example ronniec95
@ 2003-07-15  8:28 ` Pierre Weis
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre Weis @ 2003-07-15  8:28 UTC (permalink / raw)
  To: ronniec95; +Cc: caml-list

Hi,

> I'm just trying to figure out how to create a queue of a specific type in
> a .ml file. I can do it in the interpreter as:
[...]
> Declaring this in a .ml file gives 
> 
> The type of this expression, '_a Queue.t,
> contains type variables that cannot be generalized

Just add a type constraint to your definition, or add an explicit
interface file that defines the type of the queue.

let q = (Queue.create() : int Queue.t);;

Hope this helps

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/


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

end of thread, other threads:[~2003-07-15  8:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-15  8:18 [Caml-list] Queue example ronniec95
2003-07-15  8:28 ` Pierre Weis

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