Version française
Home     About     Download     Resources     Contact us    
Browse thread
module type...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] module type...
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