From: Remi VANICAT <vanicat@labri.u-bordeaux.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Haskell features in O'Caml
Date: 24 Sep 2001 21:53:25 +0200 [thread overview]
Message-ID: <87elow1i2y.dlv@wanadoo.fr> (raw)
In-Reply-To: <4F8477CFC03A71499AD8DDA428F5E114037723@basecamp.mchp.siemens.de>
Christian.Schaller@cert.siemens.de writes:
> > The correct answer might have been a reference to the module system.
> > You can specify the type of a function either in a separate *.mli-file
> > or in an explicit module declaration:
> >
> > # module M : sig
> > val mul : int -> int -> int
> > end = struct
> > let mul a b = a * b
> > end;;
> > module M : sig val mul : int -> int -> int end
> > # M.mul 2 3;;
> > - : int = 6
> > # module N : sig
> > val mul : int -> int -> int
> > end = struct
> > let mul a b = a *. b (* Arithmetic is monomorphic - no
> > type classes *)
> > end;;
> > Signature mismatch:
> > Modules do not match:
> > [...]
> >
>
> Unfortunately there seems to be a difference between explicit module
> declaration as seen above and the separation of interface and
> implementation.
>
> Since implementation is not automatically checked against the interface
> (or did I get something wrong?),
yes, you do:
test.ml :
let f x = x
test.mli :
val f : int -> float
$ ocamlc -c test.ml
I/O error: test.cmi: No such file or directory
$ ocamlc -c test.mli
$ ocamlc -c test.ml
The implementation test.ml does not match the interface test.cmi:
Values do not match: val f : 'a -> 'a is not included in val f : int -> float
> you just load you implementation (or
> compile it) without using (or compiling) the appropriate interface and there
> will be no complaint about mismatch in signature and structure.
>
> I'd prefer the compiler/desktop automatically look for interface
> definition while compiling/loading.
>
> One more or less off-topic question about interfaces: is there a way to
> see the all what's inside a module when I'm opening it using "open" (like
> "module M : sig val mul : int -> int -> int end" in above example)?
yes :
$ Module T = List
module T :
sig
external length : string -> int = "%string_length"
external get : string -> int -> char = "%string_safe_get"
external set : string -> int -> char -> unit = "%string_safe_set"
[...]
external unsafe_fill : string -> pos:int -> len:int -> char -> unit
= "fill_string" "noalloc"
end
--
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next prev parent reply other threads:[~2001-09-24 19:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-09-24 16:26 Christian.Schaller
2001-09-24 19:53 ` Remi VANICAT [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-09-24 22:51 Christian.Schaller
2001-09-25 9:15 ` Remi VANICAT
2001-09-23 23:25 Arturo Borquez
2001-09-22 14:56 Arturo Borquez
2001-09-23 16:08 ` Florian Hars
2001-09-23 16:21 ` Mattias Waldau
2001-09-23 17:50 ` Dave Mason
2001-09-24 11:14 ` Sven
2001-09-24 15:29 ` Brian Rogoff
2001-09-22 11:46 Steven Murdoch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87elow1i2y.dlv@wanadoo.fr \
--to=vanicat@labri.u-bordeaux.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox