Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] question: "('a, 'b) Hashtbl.t" and type constraint
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Baptiste Robertson <jbrobertson@f...>
Subject: [Caml-list] question: "('a, 'b) Hashtbl.t" and type constraint

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;;
      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)
types, resp., thanks to the 9th and 11th line. All I got is 

	File "", 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.


open Str;;
let string_hash = Hashtbl.create 7 and 
    regexp_hash = Hashtbl.create 7 and
    kind = "a" and
    avalue = "b" in 
  if kind = "whatever" then 
    Hashtbl.add string_hash "something" avalue
    Hashtbl.add regexp_hash "something" (regexp avalue)
[ string_hash ; regexp_hash ] ;;
To unsubscribe, mail  Archives: