caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alex Baretta <alex@barettadeit.com>
To: Ocaml <caml-list@inria.fr>
Subject: Problem with local modules
Date: Mon, 18 Apr 2005 16:02:07 +0200	[thread overview]
Message-ID: <4263BDDF.3050903@barettadeit.com> (raw)

I have written a list-of-sorted-lists merging function which takes 
advantage of a functional heap module by Jean-Christophe Filliatre. I 
would like to avoid the functorial style of the heap library by using 
local modules; however, the type system does not allow me to bind the 
"type t" of the local parameter module to a type variable, which is 
bound in the containing expression.

This is what I would like to have:

let rev_merge_list_rev_filter_append
    (cmp : 'a -> 'a -> int)
    (p : 'a -> bool)
    (ll : 'a list list)
    (accu : 'a list)
=
   let module Ordered = struct
     type t = Obj.t * (Obj.t list)
     let compare (x,tlx) (y,tly) = cmp ((Obj.obj x):'a) ((Obj.obj y):'a)
   end in
   let module Heap = Heap.Functional (Ordered)
   in
     ...


This is what I had to write.


let rev_merge_list_rev_filter_append
    (cmp : 'a -> 'a -> int)
    (p : 'a -> bool)
    (ll : 'a list list)
    (accu : 'a list)
=
   let module Ordered = struct
     type t = Obj.t * (Obj.t list)
     let compare (x,tlx) (y,tly) = cmp ((Obj.obj x):'a) ((Obj.obj y):'a)
   end in
   let module Heap = Heap.Functional (Ordered)
   in
     ...

Is this a limitation of the type theory or of the type checker? Is there 
any other way out than using the Obj module?

Alex

-- 
*********************************************************************
http://www.barettadeit.com/
Baretta DE&IT
A division of Baretta SRL

tel. +39 02 370 111 55
fax. +39 02 370 111 54

Our technology:

The Application System/Xcaml (AS/Xcaml)
<http://www.asxcaml.org/>

The FreerP Project
<http://www.freerp.org/>


                 reply	other threads:[~2005-04-18 14:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=4263BDDF.3050903@barettadeit.com \
    --to=alex@barettadeit.com \
    --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;
as well as URLs for NNTP newsgroup(s).