caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] question: "('a, 'b) Hashtbl.t" and type constraint
@ 2001-03-24 18:46 Jean-Baptiste Robertson
  2001-03-26 10:33 ` Jean-Christophe Filliatre
  0 siblings, 1 reply; 2+ messages in thread
From: Jean-Baptiste Robertson @ 2001-03-24 18:46 UTC (permalink / raw)
  To: caml-list

Hello,

OCaml 2.99 complains about the type of the following expression. After
browsing the manual, the FAQ and the like, and after trying every type
forcing I could think of, I am still unable to persuade it to accept the
following piece of code: 

      1 open Str;;
      2
      3 let string_hash = Hashtbl.create 7 and
      4     regexp_hash = Hashtbl.create 7 and
      5     kind = "a" and
      6     avalue = "b" in
      7 begin
      8   if kind = "whatever" then
      9     Hashtbl.add string_hash "something" avalue
     10   else
     11     Hashtbl.add regexp_hash "something" (regexp avalue)
     12 end;
     13 [ string_hash ; regexp_hash ] ;;

(see below for a cut-and-paste friendly version).

I expected the compiler to bind `string_hash' and `regexp_hash' to
values of the `(string,string) Hashtbl' and `(string,Str.regexp)
Hashtbl'
types, resp., thanks to the 9th and 11th line. All I got is 

	File "ex.ml", line 13, characters 16-27:
	This expression has type (string, Str.regexp) Hashtbl.t
	but is here used with type (string, string) Hashtbl.t

Replacing the 4th line by
let regexp_hash = (Hashtbl.create 7 : (string, Str.regexp) Hashtbl.t );;
doesn't help.

I may be missing the obvious. No idea.

Any help is appreciated.
TIA

jb


_____________________________
open Str;;
  
let string_hash = Hashtbl.create 7 and 
    regexp_hash = Hashtbl.create 7 and
    kind = "a" and
    avalue = "b" in 
begin
  if kind = "whatever" then 
    Hashtbl.add string_hash "something" avalue
  else 
    Hashtbl.add regexp_hash "something" (regexp avalue)
end;
[ string_hash ; regexp_hash ] ;;
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] question: "('a, 'b) Hashtbl.t" and type constraint
  2001-03-24 18:46 [Caml-list] question: "('a, 'b) Hashtbl.t" and type constraint Jean-Baptiste Robertson
@ 2001-03-26 10:33 ` Jean-Christophe Filliatre
  0 siblings, 0 replies; 2+ messages in thread
From: Jean-Christophe Filliatre @ 2001-03-26 10:33 UTC (permalink / raw)
  To: Jean-Baptiste Robertson; +Cc: caml-list


Hi,

The type error  comes from the fact  that you build in line  13 a list
containing  the   two  hash   tables,  which  have   different  types.
Consequently you got a type mismatch.

Since I do not know what you  want to do with that list, I cannot help
you  furthermore,  but  you  could  (for instance)  replace  that  two
elements list but the tuple (string_hash, regexp_hash).

Hope this helps,
-- 
Jean-Christophe FILLIATRE
  mailto:Jean-Christophe.Filliatre@lri.fr
  http://www.lri.fr/~filliatr

Jean-Baptiste Robertson writes:
 > Hello,
 > 
 > OCaml 2.99 complains about the type of the following expression. After
 > browsing the manual, the FAQ and the like, and after trying every type
 > forcing I could think of, I am still unable to persuade it to accept the
 > following piece of code: 
 > 
 >       1 open Str;;
 >       2
 >       3 let string_hash = Hashtbl.create 7 and
 >       4     regexp_hash = Hashtbl.create 7 and
 >       5     kind = "a" and
 >       6     avalue = "b" in
 >       7 begin
 >       8   if kind = "whatever" then
 >       9     Hashtbl.add string_hash "something" avalue
 >      10   else
 >      11     Hashtbl.add regexp_hash "something" (regexp avalue)
 >      12 end;
 >      13 [ string_hash ; regexp_hash ] ;;
 > 
 > (see below for a cut-and-paste friendly version).
 > 
 > I expected the compiler to bind `string_hash' and `regexp_hash' to
 > values of the `(string,string) Hashtbl' and `(string,Str.regexp)
 > Hashtbl'
 > types, resp., thanks to the 9th and 11th line. All I got is 
 > 
 > 	File "ex.ml", line 13, characters 16-27:
 > 	This expression has type (string, Str.regexp) Hashtbl.t
 > 	but is here used with type (string, string) Hashtbl.t
 > 
 > Replacing the 4th line by
 > let regexp_hash = (Hashtbl.create 7 : (string, Str.regexp) Hashtbl.t );;
 > doesn't help.
 > 
 > I may be missing the obvious. No idea.
 > 
 > Any help is appreciated.
 > TIA
 > 
 > jb
 > 
 > 
 > _____________________________
 > open Str;;
 >   
 > let string_hash = Hashtbl.create 7 and 
 >     regexp_hash = Hashtbl.create 7 and
 >     kind = "a" and
 >     avalue = "b" in 
 > begin
 >   if kind = "whatever" then 
 >     Hashtbl.add string_hash "something" avalue
 >   else 
 >     Hashtbl.add regexp_hash "something" (regexp avalue)
 > end;
 > [ string_hash ; regexp_hash ] ;;
 > -------------------
 > To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-03-26 10:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-24 18:46 [Caml-list] question: "('a, 'b) Hashtbl.t" and type constraint Jean-Baptiste Robertson
2001-03-26 10:33 ` Jean-Christophe Filliatre

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).