From: Andreas Rossberg <rossberg@ps.uni-sb.de>
To: caml-list@inria.fr
Subject: Re: Compiler translation of array indexing
Date: Mon, 24 Jan 2000 18:06:10 +0100 [thread overview]
Message-ID: <388C8682.6E3A8E4@ps.uni-sb.de> (raw)
In-Reply-To: <200001192250.XAA25766@pauillac.inria.fr>
Pierre Weis wrote:
>
> To summerize, I really would like to write
> v.(1) instead of Array.get v 1
> s.(1) instead of String.get s 1
>
> I would consider as an additional benefit of the new type system, if I
> could use:
> t.("ok") instead of Hashtbl.find t "ok",
> l.("ok") instead of List.assoc "ok" l.
Recent work by Mark Jones tries to make this work in Haskell/Hugs by
extending multi parameter type classes with dependency annotations:
http://www.cse.ogi.edu/~mpj/fds.html
Using dependency annotations, one can declare a class like (in some
mixed Haskell/Caml pseudo syntax):
class Index 'c 'i 'e | 'c -> 'i 'e where
.() : 'c -> 'i -> 'e
(note that all parameters have kind *) and instances
instance Index ('a array) int 'a
instance Index string int char
instance Index (('a,'b) Hashtbl.t) 'a 'b
instance Index (('a*'b) list) 'a 'b
These should provide the desired type-driven behaviour for indexing. The
dependency annotation ('c -> 'i 'e) in the class ensures that index and
element type are determined by the collection type. For example, the
compiler could infer the following:
[|1;2;3|].(0) : int
"hello".(3) : char
[(2,39);(4,0)].(2) : int
fun i -> "hello".(i) : int -> char
Note however, that overloading can quickly become ambiguous, even with
dependencies. While
let f x = x.(0)
would be possible and have qualified type like
(Index 'c int 'e) => 'c -> 'e,
the only slightly more involved
let g x = x.(0).(0)
would not be allowed without additional type annotations since
(Index 'c1 int 'c2, Index 'c2 int 'e) => 'c1 -> 'e
is an ambiguous type.
Best regards,
- Andreas
next prev parent reply other threads:[~2000-01-25 8:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-01-19 17:33 Simon Peyton-Jones
2000-01-19 22:50 ` Pierre Weis
2000-01-24 17:06 ` Andreas Rossberg [this message]
-- strict thread matches above, loose matches on Subject: below --
2000-01-18 16:34 David McClain
2000-01-19 14:25 ` Pierre Weis
2000-01-19 17:08 ` Markus Mottl
2000-01-19 21:17 ` Pierre Weis
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=388C8682.6E3A8E4@ps.uni-sb.de \
--to=rossberg@ps.uni-sb.de \
--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