[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Very general OCaml questions



On Fri, Feb 10, 2012 at 4:49 PM, Sebastian Probst Eide
<sebastian.probst.eide@xxxxxxxxx> wrote:
> 2) ----------------------
> If I want to define a set of high level types that should be shared between 
> all my modules and functions, how do I go about doing that?
> I tend to end up creating monolithic monsters of OCaml programs with 
> everything defined in one file, just to avoid redefining the same types in 
> all my files, and that clearly is the wrong approach :)

You can define them once in a separate module (say M) and then acces
its constructors via M.<constructor>.

e.g. :

file toto.ml:
-------
type t = Foo | Bar of int | Baz
-------

file blah.ml
-------
let x = Toto.Foo
let y = Toto.Bar 42
-------

file coucou.ml
-------
let x = Toto.Baz
-------


-- 
_______
Raphael



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.