caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] PostgreSQL and Ocaml
@ 2002-10-11 11:04 Alessandro Baretta
  2002-10-11 11:24 ` Yang Shouxun
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alessandro Baretta @ 2002-10-11 11:04 UTC (permalink / raw)
  To: Ocaml

I have found an excellent client library to access 
PostgreSQL databases from Ocaml applications. This I have 
put to use with excellent results in the development of a 
web application, together with Netcgi. However, most of the 
logic of my program is written and stored in the database as 
sql and pl/pgsql stored procedures. While SQL is overall a 
very good language to express computations in relational 
algebra, it is very weak (pratiquement, c'est nul) in 
general algorithms, so for anything more complex than a 
query one has to resort to pl/pgSQL, which is as powerful as 
an ordinary imperative language with the added bonus of 
having SQL constructs for relational algebra. What it lacks 
is type safety. After having come in contact with OCaml, I 
can hardly live with a language with no type safety.

Now I wonder: has nobody written a PostgreSQL server-side 
binding for Ocaml? I have searched Google on the subject, 
but found nothing relevant.

If nobody has, would anyone like to join me in the project 
of writing an add-in for PostgreSQL supporting Ocaml stored 
procedures? I have little experience in this, but it should 
not be too difficult: it should be a matter of writing a C 
dll which, upon initialization, starts a bytecode compiler 
and interpreter, and has callbacks through with which the 
server can request the compilation of a text string or the 
execution of a bytecode cmo blob. Although I think I might 
succeed by myself, I'd still prefer to work in company, if I 
have to.  :)

Alex

-------------------
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] 6+ messages in thread

* Re: [Caml-list] PostgreSQL and Ocaml
  2002-10-11 11:04 [Caml-list] PostgreSQL and Ocaml Alessandro Baretta
@ 2002-10-11 11:24 ` Yang Shouxun
  2002-10-11 12:31   ` Alessandro Baretta
  2002-10-11 18:53 ` Chris Hecker
  2002-10-12 12:05 ` Nicolas Cannasse
  2 siblings, 1 reply; 6+ messages in thread
From: Yang Shouxun @ 2002-10-11 11:24 UTC (permalink / raw)
  To: caml-list

Alessandro Baretta wrote:
> 
> Now I wonder: has nobody written a PostgreSQL server-side binding for 
> Ocaml? I have searched Google on the subject, but found nothing relevant.
> 

Alain Frisch has written an OCaml binding for PostgreSQL and it's even 
packaged in Debian by Stefano. See* 
*http://www.eleves.ens.fr:8080/home/frisch/soft .

Not sure that's what you're looking for or not, though.

shouxun

-------------------
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] 6+ messages in thread

* Re: [Caml-list] PostgreSQL and Ocaml
  2002-10-11 11:24 ` Yang Shouxun
@ 2002-10-11 12:31   ` Alessandro Baretta
  0 siblings, 0 replies; 6+ messages in thread
From: Alessandro Baretta @ 2002-10-11 12:31 UTC (permalink / raw)
  To: Yang Shouxun, ocaml



Yang Shouxun wrote:
> Alessandro Baretta wrote:
> 
>>
>> Now I wonder: has nobody written a PostgreSQL server-side binding for 
>> Ocaml? I have searched Google on the subject, but found nothing relevant.
>>
> 
> Alain Frisch has written an OCaml binding for PostgreSQL and it's even 
> packaged in Debian by Stefano. See* 
> *http://www.eleves.ens.fr:8080/home/frisch/soft .
> 
> Not sure that's what you're looking for or not, though.
> 

That's an excellent client side library, of which I am very 
fond. I want a PL/Ocaml server side language (procedural 
language in PG jargon).

Alex

-------------------
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] 6+ messages in thread

* Re: [Caml-list] PostgreSQL and Ocaml
  2002-10-11 11:04 [Caml-list] PostgreSQL and Ocaml Alessandro Baretta
  2002-10-11 11:24 ` Yang Shouxun
@ 2002-10-11 18:53 ` Chris Hecker
  2002-10-13 14:35   ` Alessandro Baretta
  2002-10-12 12:05 ` Nicolas Cannasse
  2 siblings, 1 reply; 6+ messages in thread
From: Chris Hecker @ 2002-10-11 18:53 UTC (permalink / raw)
  To: Alessandro Baretta, Ocaml


>If nobody has, would anyone like to join me in the project of writing an 
>add-in for PostgreSQL supporting Ocaml stored procedures? I have little 
>experience in this, but it should not be too difficult: it should be a 
>matter of writing a C dll which, upon initialization, starts a bytecode 
>compiler and interpreter, and has callbacks through with which the server 
>can request the compilation of a text string or the execution of a 
>bytecode cmo blob.

I have no time to help you with this, but I have a suggestion.  I would 
write this dll in caml and use the asmdynlink library (which, 
unfortunately, is bound rather tightly into the apparently-moribund cdk at 
this point, but it still appears to work).  I'm planning on using 
asymdynlink for some of my game work, and it appears to be just the trick 
for using caml as a dynamic scripting language (you can eval strings, load 
cmo files, the loaded caml can call native caml code transparently, 
etc.).  This would allow you to write 90% of the dll in native mode caml, 
and still dynaload programs.

There are two main issues I've found that I will probably try to solve:

1.  You need to have all the cmi files around, which is annoying and a 
logistical nightmare.  This is true of the toplevel and the regular 
bytecode dynlink library too, and it sucks.  The optimal solution would be 
to bind in all the cmis as data resources into the program.  Slightly less 
optimal but still better than nothing would be to use the -pack option, get 
a single big .cmi, and use that.  I think you'd have to -pack the whole 
standard library first, and then link with that because the modules will 
now be nested in the pack module.

2.  The asmdynlink interpreter is supposedly fairly slow (I haven't done 
any timings yet).  This is not that big of a deal for what I'm going to use 
it for, but if I find it is too slow, there are a couple options.  First, 
Fabrice has a mostly-finished JIT in the cdk version.  It's x86 only I 
think, but it might be useful.  [As an aside to Fabrice and/or Xavier, why 
didn't the JIT generate Cmm code instead of x86, and then link in the 
compiler backend from the current platform, and that way it would be 
cross-platform?  That would work, right?]  The other option is to rewrite 
the interpreter by porting the C interpreter over the the asmdynlink 
environment...that should be fairly easy and should run at the same speed 
as the regular bytecode interpreter.

Chris


-------------------
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] 6+ messages in thread

* Re: [Caml-list] PostgreSQL and Ocaml
  2002-10-11 11:04 [Caml-list] PostgreSQL and Ocaml Alessandro Baretta
  2002-10-11 11:24 ` Yang Shouxun
  2002-10-11 18:53 ` Chris Hecker
@ 2002-10-12 12:05 ` Nicolas Cannasse
  2 siblings, 0 replies; 6+ messages in thread
From: Nicolas Cannasse @ 2002-10-12 12:05 UTC (permalink / raw)
  To: Alessandro Baretta, Ocaml

> I have found an excellent client library to access
> PostgreSQL databases from Ocaml applications. This I have
> put to use with excellent results in the development of a
> web application, together with Netcgi. However, most of the
> logic of my program is written and stored in the database as
> sql and pl/pgsql stored procedures. While SQL is overall a
> very good language to express computations in relational
> algebra, it is very weak (pratiquement, c'est nul) in
> general algorithms, so for anything more complex than a
> query one has to resort to pl/pgSQL, which is as powerful as
> an ordinary imperative language with the added bonus of
> having SQL constructs for relational algebra. What it lacks
> is type safety. After having come in contact with OCaml, I
> can hardly live with a language with no type safety.

Few months ago I investigated the ability to write UDF ( User Defined
Function ) for MySQL under Win32. But it seems like this feature is only
available under *Nix versions of MySQL. The main points are the same. First
you write a C function with specific API in order to access fields and
values in a given row. Then you compile the C into a server-side DLL and
register it under MySQL with a specific SQL command which add a new SQL
keyword binded to your function.

Is there any differences with PortgreSQL ?
If only the API calls differs, should I advise you to consider having an
"opened API" design ( in order to support both PostgreSQL, MySQL, and maybe
other systems... )

> Now I wonder: has nobody written a PostgreSQL server-side
> binding for Ocaml? I have searched Google on the subject,
> but found nothing relevant.
>
> If nobody has, would anyone like to join me in the project
> of writing an add-in for PostgreSQL supporting Ocaml stored
> procedures? I have little experience in this, but it should
> not be too difficult: it should be a matter of writing a C
> dll which, upon initialization, starts a bytecode compiler
> and interpreter, and has callbacks through with which the
> server can request the compilation of a text string or the
> execution of a bytecode cmo blob. Although I think I might
> succeed by myself, I'd still prefer to work in company, if I
> have to.  :)

Although I don't have dev time for it, I would agree to share ideas and
point of view with you about this subject.

Regards,
Nicolas Cannasse

-------------------
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] 6+ messages in thread

* Re: [Caml-list] PostgreSQL and Ocaml
  2002-10-11 18:53 ` Chris Hecker
@ 2002-10-13 14:35   ` Alessandro Baretta
  0 siblings, 0 replies; 6+ messages in thread
From: Alessandro Baretta @ 2002-10-13 14:35 UTC (permalink / raw)
  To: Chris Hecker, Ocaml



Chris Hecker wrote:
> 
>> If nobody has, would anyone like to join me in the project of writing 
>> an add-in for PostgreSQL supporting Ocaml stored procedures? I have 
>> little experience in this, but it should not be too difficult: it 
>> should be a matter of writing a C dll which, upon initialization, 
>> starts a bytecode compiler and interpreter, and has callbacks through 
>> with which the server can request the compilation of a text string or 
>> the execution of a bytecode cmo blob.
> 
> 
> I have no time to help you with this, but I have a suggestion.  I would 
> write this dll in caml and use the asmdynlink library (which, 
> unfortunately, is bound rather tightly into the apparently-moribund cdk 
> at this point, but it still appears to work). ...

This is an interesting point, but the main nightmare will be 
tying in PostgreSQL code into Ocaml. You have to consider 
that PostgreSQL is the SQL engine, and necessarily the 
embedded-Ocaml interpreter/runtime-system will have to be 
able to invoke such portions of the PostgreSQL system as are 
necessary to run queries and retrieve recordsets or to open 
and use cursors. So, C calls Caml which calls C which...

This reminds me of the autogénération de Caml: 
http://caml.inria.fr/pooh.html

Alex

-------------------
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] 6+ messages in thread

end of thread, other threads:[~2002-10-13 14:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-11 11:04 [Caml-list] PostgreSQL and Ocaml Alessandro Baretta
2002-10-11 11:24 ` Yang Shouxun
2002-10-11 12:31   ` Alessandro Baretta
2002-10-11 18:53 ` Chris Hecker
2002-10-13 14:35   ` Alessandro Baretta
2002-10-12 12:05 ` Nicolas Cannasse

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