From: oleg@pobox.com
To: jonathan.roewen@gmail.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Eliminating array bounds check
Date: Thu, 7 Sep 2006 02:48:51 -0700 (PDT) [thread overview]
Message-ID: <20060907094851.5EA15ABF9@Adric.metnet.fnmoc.navy.mil> (raw)
In-Reply-To: <ad8cfe7e0609052215y52c613b6r6208e43644421bc1@mail.gmail.com>
> > val test = let local structure A = Kernel(val a = ...)
> > open A in ... end in ...
> >
>
> I don't understand what the 'generative' part means, but are modules
> defined inside a let binding equivalent to the above?
In OCaml, functors behave like pure functions: an application of a
functor to identical arguments yields structures with compatible
types. Not so in SML (with strong sealing):
http://www.cs.cmu.edu/~crary/papers/2003/thoms/thoms.pdf
Please see Figs 6 and 7 in that paper.
Here's a sample demonstration:
In Ocaml:
module type S = sig type tt end;;
module SI : S = struct type tt = unit end;;
module Foo (X : S) : sig type t val v : t end
= struct type t = int let v = 1 end;;
let module M = struct
module M1 = Foo(SI)
let x = M1.v
module M2 = Foo(SI)
let y = M2.v
let res = x == y
end in M.res
;;
In SML (poly/ML):
signature S = sig type tt end;
structure SI : S = struct type tt = unit end;
functor Foo (X : S) :> sig type t val v : t end
= struct type t = int val v = 1 end;
(* A function that takes two arguments of the same type *)
fun cmp (x:'t) (y:'t) = true;
local structure M1 = Foo(SI) val x = M1.v
structure M2 = Foo(SI) val y = M2.v
in val t = cmp x y end;
# Error:
Can't unify M1.t with M2.t (Different type constructors) Found near cmp(x)(y)
In retrospect, for bsearch application, either functor would have
sufficed. However, a generative functor seems cleaner (and, in a
higher-ranked emulation) more easily formalizable.
next prev parent reply other threads:[~2006-09-07 9:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-04 1:00 oleg
2006-09-04 7:22 ` [Caml-list] " Alain Frisch
2006-09-04 7:42 ` Alain Frisch
2006-09-06 5:03 ` oleg
2006-09-06 5:15 ` Jonathan Roewen
2006-09-07 9:48 ` oleg [this message]
2006-09-04 9:43 ` skaller
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=20060907094851.5EA15ABF9@Adric.metnet.fnmoc.navy.mil \
--to=oleg@pobox.com \
--cc=caml-list@inria.fr \
--cc=jonathan.roewen@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).