<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/10/ef7ea5a38d2bceb896eb567f1eff1764"
  from="Andrew Bagdanov &lt;andrew@s...&gt;"
  author="Andrew Bagdanov"
  date="2003-10-24T12:25:11"
  subject="[Caml-list] Type abstraction question"
  prev="2003/10/bc22b36f43b4dd5f6d7af456fd0801fc"
  next="2003/10/f70a630abcb73995f40868e5b4aedd5d"
  prev-thread="2003/10/2e8a6962baf66f1c24c5f132e0e4d98a"
  next-thread="2003/10/7c4dddaeb54d671b32d64d9643af3fda"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Type abstraction question">
<msg 
  url="2003/10/ef7ea5a38d2bceb896eb567f1eff1764"
  from="Andrew Bagdanov &lt;andrew@s...&gt;"
  author="Andrew Bagdanov"
  date="2003-10-24T12:25:11"
  subject="[Caml-list] Type abstraction question">
</msg>
</thread>

<contents>
Hello all,

I'm having a bit of difficulty getting the sort of type abstraction
I want.

I have the following sort of module:

 module type Alg =
   sig
     type t
     type bin_t = t -&gt; t -&gt; t
     val add : bin_t
     val sub : bin_t
   end

which just encapsulates a domain and a few operations that can be
performed over values.  What I want to do is expose the type "t" but
_not_ "bin_t" to the world.  The specific reason I want this is so
that people can only apply functors like the following:

 module PairLifter :
   functor ( A : Alg ) -&gt;
     functor ( Op : sig val op : A.bin_t end ) -&gt;
   sig
     val op : (A.t * A.t) -&gt; (A.t * A.t) -&gt; (A.t * A.t)
   end

with operations explicitly defined in implementations of type Alg.
That is, assuming there is an implementation of:

 module IntAlg : Alg with type t = int

then I want:

 module PairAdd = PairLifter(IntAlg)(struct let op = IntAlg.add end)

to work fine, but:

 module PairAdd = PairLifter(IntAlg)(struct let op = ( + ) end)

to fail.  It is somewhat crucial for the type "t" to be exposed,
however, to simplify passing of constants, etc.

Anyway, this is a simplified version of what I'm trying to do, and I
fear there might be fundamental problems with my understanding of the
type system.  So, feel free to hold my hand...

Thanks,

-Andy


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

