* How to expose sum type constructors to an interface
@ 2007-10-18 0:16 Felix Dorner
2007-10-18 0:41 ` [Caml-list] " Chris King
2007-10-18 0:45 ` Julien Moutinho
0 siblings, 2 replies; 4+ messages in thread
From: Felix Dorner @ 2007-10-18 0:16 UTC (permalink / raw)
To: caml-list
Hi,
although this might really be a beginner´ s question I´ ll post it here
and risk to be eaten by the big fish around here...
I am starting to learn ocaml and tonight´ s lesson is how to handle
modules/interfaces. I come up with this:
In my implementation file module.ml I define: type aType = A | B
How I now need to expose this Type and its constructors to the
interface module.mli, because some of the functions declared in the
interface take a parameter of type "aType". How can I do this?
Thanks for any help,
Felix
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] How to expose sum type constructors to an interface
2007-10-18 0:16 How to expose sum type constructors to an interface Felix Dorner
@ 2007-10-18 0:41 ` Chris King
2007-10-18 0:45 ` Julien Moutinho
1 sibling, 0 replies; 4+ messages in thread
From: Chris King @ 2007-10-18 0:41 UTC (permalink / raw)
To: Felix Dorner; +Cc: caml-list
On 10/17/07, Felix Dorner <felix_do@web.de> wrote:
> although this might really be a beginner´ s question I´ ll post it here
> and risk to be eaten by the big fish around here...
Well, this small fish is going to nudge you in the direction of the
O'Caml beginners list
(http://tech.groups.yahoo.com/group/ocaml_beginners/) for future
"beginner" questions :)
> In my implementation file module.ml I define: type aType = A | B
> How I now need to expose this Type and its constructors to the
> interface module.mli, because some of the functions declared in the
> interface take a parameter of type "aType". How can I do this?
Just add "type aType = A | B" to the module.mli file. As a side note,
if you ever want to see what the inferred signature (i.e. the
signature of a .ml with no .mli) of a module is, run ocaml -i on the
.ml file and it will spit the inferred .mli to standard output.
HTH,
Chris
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] How to expose sum type constructors to an interface
2007-10-18 0:16 How to expose sum type constructors to an interface Felix Dorner
2007-10-18 0:41 ` [Caml-list] " Chris King
@ 2007-10-18 0:45 ` Julien Moutinho
2007-10-18 5:48 ` Christophe Raffalli
1 sibling, 1 reply; 4+ messages in thread
From: Julien Moutinho @ 2007-10-18 0:45 UTC (permalink / raw)
To: caml-list
On Thu, Oct 18, 2007 at 02:16:50AM +0200, Felix Dorner wrote:
> In my implementation file module.ml I define: type aType = A | B
> How I now need to expose this Type and its constructors to the interface
> module.mli, because some of the functions declared in the interface take a
> parameter of type "aType". How can I do this?
The toplevel or the flag
-i Print inferred interface
may help you :)
% cat file.ml
type a_type = A | B
let f =
function
| A -> B
| _ -> A
% ocamlc -i file.ml
type a_type = A | B
val f : a_type -> a_type
A few pointers that may help too:
http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora130.html#toc180
http://caml.inria.fr/pub/docs/manual-ocaml/manual018.html#@manual.kwd135
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] How to expose sum type constructors to an interface
2007-10-18 0:45 ` Julien Moutinho
@ 2007-10-18 5:48 ` Christophe Raffalli
0 siblings, 0 replies; 4+ messages in thread
From: Christophe Raffalli @ 2007-10-18 5:48 UTC (permalink / raw)
To: Julien Moutinho; +Cc: caml-list
[-- Attachment #1.1: Type: text/plain, Size: 1136 bytes --]
Julien Moutinho a écrit :
> On Thu, Oct 18, 2007 at 02:16:50AM +0200, Felix Dorner wrote:
>
>> In my implementation file module.ml I define: type aType = A | B
>> How I now need to expose this Type and its constructors to the interface
>> module.mli, because some of the functions declared in the interface take a
>> parameter of type "aType". How can I do this?
>>
You may also choose not to have a .mli file at all. This is equivalent
to using the result of ocaml -i as mli
file. An mli file is needed if you want to make your type abstract or if
you want to hide some functions.
Cheers,
--
Christophe Raffalli
Universite de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex
tel: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI
---------------------------------------------
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution
can check this signature. The public key is
stored on www.keyserver.net
---------------------------------------------
[-- Attachment #1.2: Christophe.Raffalli.vcf --]
[-- Type: text/x-vcard, Size: 310 bytes --]
begin:vcard
fn:Christophe Raffalli
n:Raffalli;Christophe
org:LAMA (UMR 5127)
email;internet:christophe.raffalli@univ-savoie.fr
title;quoted-printable:Ma=C3=AEtre de conf=C3=A9rences
tel;work:+33 4 79 75 81 03
note:http://www.lama.univ-savoie.fr/~raffalli
x-mozilla-html:TRUE
version:2.1
end:vcard
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-10-18 5:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-18 0:16 How to expose sum type constructors to an interface Felix Dorner
2007-10-18 0:41 ` [Caml-list] " Chris King
2007-10-18 0:45 ` Julien Moutinho
2007-10-18 5:48 ` Christophe Raffalli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox