Patrick M Doane | 1 Jul 2001 07:32

Re: "Re: A G'Caml question" + additional info

On Sat, 30 Jun 2001, Brian Rogoff wrote:

> On Sat, 30 Jun 2001, Patrick M Doane wrote:
> > On Sat, 30 Jun 2001, John Max Skaller wrote:
> > > 	G'caml makes it easier to write readable algorithms,
> > > and to do 'cut and paste' genericity. But it can't do what
> > > you can do in C++. 
> > I agree.  Although I'm not advocating that it do everything you can do in
> > C++.
> 
> Less talk, more coding examples please.

Here's a simple example motivating my thoughts in this discussion:

generic get = case
  | string -> int -> char => String.get

let print_first x = get x 0

generic get = case
  | include get
  | $a array -> int -> $a => Array.get
;;
print_first [|0|]

As far as I can tell, there are no current plans for this kind of code
to work with G'caml.

> GCaml polymorphism is remarkably
> easy to use. A while ago, when there was some discussion of overloading
(Continue reading)

Ian Zimmerman | 1 Jul 2001 23:02
Picon

custom linking not working


What am I doing wrong here???

itz:~# ocamlc -linkall -custom toplevellib.cma /usr/lib/ocaml/libgraphics.a \
        topmain.cmo -o ocaml.graphics
itz:~# ./ocaml.graphics
        Objective Caml version 3.01

# #load "/usr/lib/ocaml/graphics.cma";;
The external function `gr_set_text_size' is not available
# 
itz:~# ocamlc -v
The Objective Caml compiler, version 3.01
Standard library directory: /usr/lib/ocaml
itz:~# nm /usr/lib/ocaml/libgraphics.a | grep gr_set_text_size 
000000bc T gr_set_text_size

--

-- 
Ian Zimmerman, Oakland, California, U.S.A.
EngSoc adopts market economy: cheap is wasteful, efficient is expensive.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request <at> inria.fr  Archives: http://caml.inria.fr

Jacques Garrigue | 2 Jul 2001 01:19
Picon
Picon

Re: custom linking not working

From: Ian Zimmerman <itz <at> speakeasy.org>

> What am I doing wrong here???
> 
> itz:~# ocamlc -linkall -custom toplevellib.cma /usr/lib/ocaml/libgraphics.a \
>         topmain.cmo -o ocaml.graphics

You shouldn't use libgraphics.a, but graphics.cma.

The right invocation is much simpler:

    ocamlmktop graphics.cma -o ocaml.graphics

Jacques Garrigue
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request <at> inria.fr  Archives: http://caml.inria.fr

Ian Zimmerman | 2 Jul 2001 01:24
Picon

Re: custom linking not working


itz> What am I doing wrong here???
itz> 
itz> itz:~# ocamlc -linkall -custom toplevellib.cma
itz> /usr/lib/ocaml/libgraphics.a \ topmain.cmo -o ocaml.graphics

Jacques> You shouldn't use libgraphics.a, but graphics.cma.  The right
Jacques> invocation is much simpler:

Jacques> ocamlmktop graphics.cma -o ocaml.graphics

Well, I know that would work, of course :-)

But what I was trying to do was precisely to avoid linking the
bytecode at build time.  Is that impossible?

--

-- 
Ian Zimmerman, Oakland, California, U.S.A.
EngSoc adopts market economy: cheap is wasteful, efficient is expensive.
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request <at> inria.fr  Archives: http://caml.inria.fr

Jeremy Fincher | 2 Jul 2001 08:52
Picon
Favicon

Some more code written by a newbie to be reviewed by *real* O'Caml coders :)

I'm fairly new to O'Caml, and I hope that a few more experienced O'Caml 
programmers can review some of the code I've written to show me how things 
can be done better, what parts I've done that stray from O'Caml idiom, and 
so on...so here's some more code I hope a few people will take the time to 
review :)

I'm coming from Python, so I figured one fairly simple thing I can do to 
ease the transition and get some practice working with O'Caml is to rewrite 
some of the more featureful python modules in O'Caml.  Here's an 
implementation of most of the useful (read: stuff I've used :)) functions 
from the Python "string" module.  Don't worry if you don't know Python or 
that module -- I've written an interface file that comments what each 
function is supposed to do.

Here are the files:

http://members.aol.com/jemfinch02/py_string.mli
http://members.aol.com/jemfinch02/py_string.ml

The one thing I think would be better done already is that the functions 
should probably take the string they're to operate on as their last 
argument, so new functions can be created more easily by partial function 
application.

Anyway, if anyone does review this code, feel free to rip it apart -- I'm 
far more concerned with becoming a better O'Caml programmer than with 
keeping my pride :)

Jeremy

(Continue reading)

Jeremy Fincher | 2 Jul 2001 09:36
Picon
Favicon

Two quick questions.

First: I looked at the source code to the Printf module to see exactly how 
Printf.printf does type checking on the format strings, since I'd like to 
implement something similar (for reimplementing the "struct" python module, 
which uses format strings to pack/unpack arbitrary binary data) but I 
honestly had no idea how it worked.  Is something like what Printf.printf 
does way too "deep magic" for a newbie to O'Caml to do, or are there any 
good explanations of how it does what it does?

Second: Are there any good examples of using ocamllex/ocamlyacc to build 
abstract syntax trees?  I've seen ASTs built from streams in the Caml-light 
manual, and I've seen examples of ocamllex/ocamlyacc used to parse simple 
languages that don't really need an AST, but I can't find any examples (with 
explanations, of course :)) of ocamllex/ocamlyacc being used to actually 
create abstract syntax trees for a given grammar.

Thanks,
Jeremy
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request <at> inria.fr  Archives: http://caml.inria.fr

Xavier Leroy | 2 Jul 2001 09:45
Picon
Picon
Favicon

Re: custom linking not working

> What am I doing wrong here???
> 
> itz:~# ocamlc -linkall -custom toplevellib.cma /usr/lib/ocaml/libgraphics.a \
>         topmain.cmo -o ocaml.graphics
> itz:~# ./ocaml.graphics
>         Objective Caml version 3.01
> 
> # #load "/usr/lib/ocaml/graphics.cma";;
> The external function `gr_set_text_size' is not available
> # 
> itz:~# ocamlc -v
> The Objective Caml compiler, version 3.01
> Standard library directory: /usr/lib/ocaml
> itz:~# nm /usr/lib/ocaml/libgraphics.a | grep gr_set_text_size 
> 000000bc T gr_set_text_size

With -custom, only C primitives actually referenced from Caml code get
linked in.  At the very least, you need to link a Caml object file that
just declares "external" all the C primitives you're interested in.

All the best,

- Xavier Leroy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request <at> inria.fr  Archives: http://caml.inria.fr

Chris Hecker | 2 Jul 2001 10:03

Re: Two quick questions.


>First: I looked at the source code to the Printf module to see exactly how Printf.printf does type checking
on the format strings, since I'd like to implement something similar (for reimplementing the "struct"
python module, which uses format strings to pack/unpack arbitrary binary data) but I honestly had no idea
how it worked.  Is something like what Printf.printf does way too "deep magic" for a newbie to O'Caml to do,
or are there any good explanations of how it does what it does?

It is "deep magic", in the sense that it's hacked into the compiler directly.  You can use some of the hacks for
your own purposes, but you can't change the format string format.

Chris

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request <at> inria.fr  Archives: http://caml.inria.fr

wakita | 2 Jul 2001 13:53
Picon
Favicon

Re: Two quick questions.


You might be interested in "Functional unparsing" by Olivier Danvy.

http://www.brics.dk/RS/98/12/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request <at> inria.fr  Archives: http://caml.inria.fr

Xavier Leroy | 2 Jul 2001 14:01
Picon
Picon
Favicon

Re: linking ocaml with java

> If it is possible to link ocaml with java, could someone point me to some
> documentation or provide the instructions.

A preliminary Caml/Java interface (via the Java Native Interface) is
available at http://caml.inria.fr/distrib/camljava-0.1.tar.gz

This is a JNI-level interface: it lets you do pretty much everything,
but is not type safe and a bit heavy in places.  A higher-level interface
providing a more direct, type-safe mapping between Java classes and
Caml classes, is planned at some point.

- Xavier Leroy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request <at> inria.fr  Archives: http://caml.inria.fr


Gmane