Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Pietro Abate <Pietro.Abate@anu.edu.au>
Cc: ocaml ml <caml-list@inria.fr>
Subject: Re: [Caml-list] module type...
Date: 11 Nov 2004 19:56:10 +1100	[thread overview]
Message-ID: <1100163369.2579.70.camel@pelican.wigram> (raw)
In-Reply-To: <20041111083547.GA13116@pulp.anu.edu.au>

On Thu, 2004-11-11 at 19:35, Pietro Abate wrote:
> Hi all,
> I've a problem that boils down to this code below.

> module type ElType =
>     sig
>         type t
>     end
> ;;
> module TermType : ElType =
>     struct
>         type t = int
>     end
> ;;
> let l : TermType.t list = [1;2];;
> 
> (* -------------- *)
> 
> now the compiler tells me that:
> 
> This expression has type int but is here used with type TermType.t
> 
> but TermType.t should be unified with int...
> 

By coercing TermType to ElType, you have coerced 'int' to 't',
where 't' is an abstract type, in other words the coercion is hiding
the representation. There are two ways around this

(a) don't hide the representation, put

	type t = int

into the module type ElType as well.

(b) add a type constructor function to the module  TermType

	let term_of_int i = i

with declaration in ElType:

	val term_of_int: int -> t


-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net




  reply	other threads:[~2004-11-11  8:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-11  8:35 Pietro Abate
2004-11-11  8:56 ` skaller [this message]
2004-11-11  9:09   ` [Caml-list] " Pietro Abate
2004-11-11  9:48     ` Virgile Prevosto
2004-11-12 16:11       ` Specifying abstract type in a record josh
2004-11-12 16:33         ` [Caml-list] " Luc Maranget
2004-11-12 16:37         ` Aleksey Nogin
2004-11-12 16:37         ` Richard Jones
2004-11-12 16:40         ` Andrew Bagdanov
2004-11-12 16:44         ` Matt Gushee

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=1100163369.2579.70.camel@pelican.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=Pietro.Abate@anu.edu.au \
    --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