caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Interface between Ocaml and C++
@ 2004-06-19  4:56 Gu Nu
  2004-06-19  7:29 ` art yerkes
  0 siblings, 1 reply; 8+ messages in thread
From: Gu Nu @ 2004-06-19  4:56 UTC (permalink / raw)
  To: caml-list

Hi, all

Does anybody know how to deal with C++ classes, such
as vectors, maps, in Ocaml? It seems that currently
Ocaml can  only support the interoperation of C. So
the first step is to try encapusuate a C++ class with
C interface, then write C interface for Ocaml.
However, it is so inconvient for std classes. Does
anybody has any better ideas?

Thanks a lot!

Andy


		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

-------------------
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Interface between Ocaml and C++
  2004-06-19  4:56 [Caml-list] Interface between Ocaml and C++ Gu Nu
@ 2004-06-19  7:29 ` art yerkes
  2004-06-21 19:24   ` Eray Ozkural
  0 siblings, 1 reply; 8+ messages in thread
From: art yerkes @ 2004-06-19  7:29 UTC (permalink / raw)
  To: Gu Nu; +Cc: caml-list

On Fri, 18 Jun 2004 21:56:05 -0700 (PDT)
Gu Nu <gnu04@yahoo.com> wrote:

> Hi, all
> 
> Does anybody know how to deal with C++ classes, such
> as vectors, maps, in Ocaml? It seems that currently
> Ocaml can  only support the interoperation of C. So
> the first step is to try encapusuate a C++ class with
> C interface, then write C interface for Ocaml.
> However, it is so inconvient for std classes. Does
> anybody has any better ideas?
> 
> Thanks a lot!
> 
> Andy
> 

The SWIG module for Ocaml has support for a few STL
types.  If you use those interfaces as a guide, you
could add support for more if the automatic wrapping
doesn't suit.

SWIG isn't perfect for everyone but some needs are
met very well, including using templates.

Look at http://www.swig.org/
-- 
Hey, Adam Smith, keep your invisible hands to yourself!

-------------------
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Interface between Ocaml and C++
  2004-06-19  7:29 ` art yerkes
@ 2004-06-21 19:24   ` Eray Ozkural
  2004-06-22  6:41     ` art yerkes
  0 siblings, 1 reply; 8+ messages in thread
From: Eray Ozkural @ 2004-06-21 19:24 UTC (permalink / raw)
  To: art yerkes; +Cc: Gu Nu, caml-list

On Saturday 19 June 2004 10:29, art yerkes wrote:
> The SWIG module for Ocaml has support for a few STL
> types.  If you use those interfaces as a guide, you
> could add support for more if the automatic wrapping
> doesn't suit.
>
> SWIG isn't perfect for everyone but some needs are
> met very well, including using templates.
>
> Look at http://www.swig.org/

How does it handle convert C++ templates to ocaml code, I wonder. I had a 
design in my mind, but it required quite a bit of monkeying around. What's 
their solution?

Regards,

-- 
Eray Ozkural (exa) <erayo@cs.bilkent.edu.tr>
Comp. Sci. Dept., Bilkent University, Ankara  KDE Project: http://www.kde.org
http://www.cs.bilkent.edu.tr/~erayo  Malfunction: http://malfunct.iuma.com
GPG public key fingerprint: 360C 852F 88B0 A745 F31B  EA0F 7C07 AE16 874D 539C

-------------------
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Interface between Ocaml and C++
  2004-06-21 19:24   ` Eray Ozkural
@ 2004-06-22  6:41     ` art yerkes
  2004-06-22 11:14       ` Eray Ozkural
  0 siblings, 1 reply; 8+ messages in thread
From: art yerkes @ 2004-06-22  6:41 UTC (permalink / raw)
  To: erayo; +Cc: exa, gnu04, caml-list

On Mon, 21 Jun 2004 22:24:07 +0300
Eray Ozkural <exa@kablonet.com.tr> wrote:

> On Saturday 19 June 2004 10:29, art yerkes wrote:
> > The SWIG module for Ocaml has support for a few STL
> > types.  If you use those interfaces as a guide, you
> > could add support for more if the automatic wrapping
> > doesn't suit.
> >
> > SWIG isn't perfect for everyone but some needs are
> > met very well, including using templates.
> >
> > Look at http://www.swig.org/
> 
> How does it handle convert C++ templates to ocaml code, I wonder. I had a 
> design in my mind, but it required quite a bit of monkeying around. What's 
> their solution?

The current solution is to specify which specializations of a given template
will be needed, after which the specialized template classes are treated as
ordinary classes.
-- 
Hey, Adam Smith, keep your invisible hands to yourself!

-------------------
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Interface between Ocaml and C++
  2004-06-22  6:41     ` art yerkes
@ 2004-06-22 11:14       ` Eray Ozkural
  2004-06-22 13:36         ` art yerkes
  0 siblings, 1 reply; 8+ messages in thread
From: Eray Ozkural @ 2004-06-22 11:14 UTC (permalink / raw)
  To: art yerkes; +Cc: gnu04, caml-list

On Tuesday 22 June 2004 09:41, art yerkes wrote:
> On Mon, 21 Jun 2004 22:24:07 +0300
>
> Eray Ozkural <exa@kablonet.com.tr> wrote:
> > On Saturday 19 June 2004 10:29, art yerkes wrote:
> > > The SWIG module for Ocaml has support for a few STL
> > > types.  If you use those interfaces as a guide, you
> > > could add support for more if the automatic wrapping
> > > doesn't suit.
> > >
> > > SWIG isn't perfect for everyone but some needs are
> > > met very well, including using templates.
> > >
> > > Look at http://www.swig.org/
> >
> > How does it handle convert C++ templates to ocaml code, I wonder. I had a
> > design in my mind, but it required quite a bit of monkeying around.
> > What's their solution?
>
> The current solution is to specify which specializations of a given
> template will be needed, after which the specialized template classes are
> treated as ordinary classes.

OK. Imagine client ocaml code that uses template class C < T >. I had imagined 
that the specializations in the ocaml code ( C < int >, C < vector<float> 
>, ... ) could be determined automatically, after which the specializations 
are generated in C++ stub code, and linked in... So I guess I had in mind a 
more generic version of SWIG's approach, however I doubt this won't be a good 
mapping.... Can you guys imagine any other alternatives, or should we avoid 
templates in C++ libraries that want an ocaml binding (like KDE) ?

Cheers,

-- 
Eray Ozkural (exa) <erayo@cs.bilkent.edu.tr>
Comp. Sci. Dept., Bilkent University, Ankara  KDE Project: http://www.kde.org
http://www.cs.bilkent.edu.tr/~erayo  Malfunction: http://malfunct.iuma.com
GPG public key fingerprint: 360C 852F 88B0 A745 F31B  EA0F 7C07 AE16 874D 539C

-------------------
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Interface between Ocaml and C++
  2004-06-22 11:14       ` Eray Ozkural
@ 2004-06-22 13:36         ` art yerkes
  2004-06-22 18:44           ` Eray Ozkural
  0 siblings, 1 reply; 8+ messages in thread
From: art yerkes @ 2004-06-22 13:36 UTC (permalink / raw)
  To: erayo; +Cc: exa, gnu04, caml-list

On Tue, 22 Jun 2004 14:14:04 +0300
Eray Ozkural <exa@kablonet.com.tr> wrote:

> On Tuesday 22 June 2004 09:41, art yerkes wrote:
> > On Mon, 21 Jun 2004 22:24:07 +0300
> >
> > Eray Ozkural <exa@kablonet.com.tr> wrote:
> > > On Saturday 19 June 2004 10:29, art yerkes wrote:
> > > > The SWIG module for Ocaml has support for a few STL
> > > > types.  If you use those interfaces as a guide, you
> > > > could add support for more if the automatic wrapping
> > > > doesn't suit.
> > > >
> > > > SWIG isn't perfect for everyone but some needs are
> > > > met very well, including using templates.
> > > >
> > > > Look at http://www.swig.org/
> > >
> > > How does it handle convert C++ templates to ocaml code, I wonder. I had a
> > > design in my mind, but it required quite a bit of monkeying around.
> > > What's their solution?
> >
> > The current solution is to specify which specializations of a given
> > template will be needed, after which the specialized template classes are
> > treated as ordinary classes.
> 
> OK. Imagine client ocaml code that uses template class C < T >. I had imagined 
> that the specializations in the ocaml code ( C < int >, C < vector<float> 
> >, ... ) could be determined automatically, after which the specializations 
> are generated in C++ stub code, and linked in... So I guess I had in mind a 
> more generic version of SWIG's approach, however I doubt this won't be a good 
> mapping.... Can you guys imagine any other alternatives, or should we avoid 
> templates in C++ libraries that want an ocaml binding (like KDE) ?

In my experience, the C++ and ocaml type systems are different enough that
determining specializations from caml code won't work well.

Consider that:

std::set<const char *>
std::set<char [18]>
std::set<std::string>

are all different specializations of std::set on various representations of
string in C++.  The syntax to choose among them may not be easy for a user
to write and keep track of.
-- 
Hey, Adam Smith, keep your invisible hands to yourself!

-------------------
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Interface between Ocaml and C++
  2004-06-22 13:36         ` art yerkes
@ 2004-06-22 18:44           ` Eray Ozkural
  2004-06-22 23:06             ` Brandon J. Van Every
  0 siblings, 1 reply; 8+ messages in thread
From: Eray Ozkural @ 2004-06-22 18:44 UTC (permalink / raw)
  To: art yerkes; +Cc: gnu04, caml-list

On Tuesday 22 June 2004 16:36, art yerkes wrote:
> In my experience, the C++ and ocaml type systems are different enough that
> determining specializations from caml code won't work well.
>
> Consider that:
>
> std::set<const char *>
> std::set<char [18]>
> std::set<std::string>
>
> are all different specializations of std::set on various representations of
> string in C++.  The syntax to choose among them may not be easy for a user
> to write and keep track of.

I agree. What's worse, these combinatorial types can accept only C++ types as 
parameters. How to reliably specify that in ocaml client code, it's almost 
impossible to know...

Maybe SWIG's approach is a good middleground then? But it makes me wonder, why 
should I want to use C++ stdlib if I have ocaml? >:-)

The alternative I thought was a syntax extension to handle it for class and 
function templates. But I don't think it's going to work out, either. 

Regards,

-- 
Eray Ozkural (exa) <erayo@cs.bilkent.edu.tr>
Comp. Sci. Dept., Bilkent University, Ankara  KDE Project: http://www.kde.org
http://www.cs.bilkent.edu.tr/~erayo  Malfunction: http://malfunct.iuma.com
GPG public key fingerprint: 360C 852F 88B0 A745 F31B  EA0F 7C07 AE16 874D 539C

-------------------
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [Caml-list] Interface between Ocaml and C++
  2004-06-22 18:44           ` Eray Ozkural
@ 2004-06-22 23:06             ` Brandon J. Van Every
  0 siblings, 0 replies; 8+ messages in thread
From: Brandon J. Van Every @ 2004-06-22 23:06 UTC (permalink / raw)
  To: caml

Eray Ozkural wrote:
>
> Maybe SWIG's approach is a good middleground then? But it
> makes me wonder, why
> should I want to use C++ stdlib if I have ocaml? >:-)

Indeed, the whole reason I went looking for HLLs is my unwillingness to
deal with C++ STL.  I find myself asking, "When do I get off this C++
train wreck?"  It's an evolutionary dead end.


Cheers,                         www.indiegamedesign.com
Brandon Van Every               Seattle, WA

20% of the world is real.
80% is gobbledygook we make up inside our own heads.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.708 / Virus Database: 464 - Release Date: 6/18/2004

-------------------
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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-06-22 22:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-19  4:56 [Caml-list] Interface between Ocaml and C++ Gu Nu
2004-06-19  7:29 ` art yerkes
2004-06-21 19:24   ` Eray Ozkural
2004-06-22  6:41     ` art yerkes
2004-06-22 11:14       ` Eray Ozkural
2004-06-22 13:36         ` art yerkes
2004-06-22 18:44           ` Eray Ozkural
2004-06-22 23:06             ` Brandon J. Van Every

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).