From: Jean-Baptiste Robertson <jbrobertson@free.fr>
To: caml-list@inria.fr
Subject: [Caml-list] question: "('a, 'b) Hashtbl.t" and type constraint
Date: Sat, 24 Mar 2001 18:46:28 +0000 [thread overview]
Message-ID: <3ABCEB84.9D309E90@free.fr> (raw)
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
next reply other threads:[~2001-03-26 9:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-24 18:46 Jean-Baptiste Robertson [this message]
2001-03-26 10:33 ` Jean-Christophe Filliatre
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=3ABCEB84.9D309E90@free.fr \
--to=jbrobertson@free.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