caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: "Mr. Herr" <misterherr@freenet.de>
Cc: caml-list@inria.fr
Subject: AW: [Caml-list] ocamlfind? how to compile
Date: Sun, 14 Apr 2013 11:31:19 +0200	[thread overview]
Message-ID: <1365931879.13299.0@samsung> (raw)
In-Reply-To: <51686208.9020801@freenet.de> (from misterherr@freenet.de on Fri Apr 12 21:35:36 2013)

Am 12.04.2013 21:35:36 schrieb(en) Mr. Herr:
> 
> Am 12.04.2013 18:19, schrieb David Allsopp:
> > Mr. Herr wrote:
> >> I did not understand how the helpers for compilation are supposed  
> to work.
> >>
> >> For example I have a script that executes external programs, and  
> needs the
> >> Unix module.
> >>
> >> For script execution I have in the top of my script: #load  
> "unix.cma";;
> > Good "trick" for findlib is to add:
> > 	#use "topfind"
> > to ~/.ocamlinit (create it, if necessary) and then in future  
> toploops you just say
> > 	#require "unix";;
> > instead. Useful when you start using packages which depend on other  
> packages...
> >
> >> This must be removed for ocamlc or ocamlopt to work, right?  
> Annoying.
> > Yes and no - a way around it is to create a wrapper script for  
> debugging in the toploop which loads all the required libraries (or  
> just have libraries you usually need loaded via .ocamlinit). I think  
> it's fairly unusual that you have something that's actively intended  
> for both the toploop *and* separate compilation so it's usually just  
> a matter of making debugging easier in the toploop with a little  
> script.
> >
> The response goes to the list...
> 
> I am using a lot of scripting, and you could perfectly well execute  
> the ml scripts
> with a #!/usr/bin/ocaml line on top. The idea is that scripts are not  
> "finished"
> (or less finished, and not documented) compared to programs, and that  
> you read and
> adjust the source to your instant need.
> 
> My findings say that scripted ml is only a little bit slower than  
> bytecode,

It should be exactly the same speed. The same bytecode interpreter is  
running.

> but has a
> bigger memory requirement. This matches or is better than a lot of  
> _very_
> popular scripting languages. Additionally you can compile, even to  
> native code.
> 
> If only it was not so unfinished. I am just writing exec functions,  
> it should be
> rather easy to capture "Reference to undefined global `Unix' " and  
> repair it.

This is just not the way it is supposed to work. OCaml is primarily a  
compiler language, and scripting only an add-on mode, which is mainly  
useful for testing, or as driver, but not really beyond that.

The best you can do here with standard utilities is to split your  
script into two files:

- One "loader" that contains the scripting directives to load
   everything, e.g.

   #use "topfind";;
   #require "unix";;
   #use "impl.ml";;

- The real implementation (impl.ml) not using any directives. This
   implementation can be independently compiled with ocamlc or ocamlopt.

> Has this not been done?? What is ocamlfind for?

ocamlfind is only a wrapper around the compiler, basically it  
translates -package options into the list of compiler switches requires  
to link a package. ocamlfind cannot change the language.

See also the discussion here:

https://ocaml.janestreet.com/?q=node/80

Maybe Martin's utility ocamlscript is also useful for you:

http://mjambon.com/ocamlscript.html

Gerd

> 
> 
> /Str.
> 
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
> 
> 



-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
Creator of GODI and camlcity.org.
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------

      reply	other threads:[~2013-04-14  9:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11 21:59 [Caml-list] [ANN] Merlin 1.0 released Frédéric Bour
2013-04-12  1:14 ` Francois Berenger
2013-04-13 16:57   ` Frédéric Bour
2013-04-12 16:01 ` [Caml-list] ocamlfind? how to compile Mr. Herr
2013-04-12 16:19   ` David Allsopp
2013-04-12 17:09     ` Mr. Herr
2013-04-12 18:17       ` David Allsopp
2013-04-12 18:51         ` Mr. Herr
2013-04-12 19:35     ` Mr. Herr
2013-04-14  9:31       ` Gerd Stolpmann [this message]

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=1365931879.13299.0@samsung \
    --to=info@gerd-stolpmann.de \
    --cc=caml-list@inria.fr \
    --cc=misterherr@freenet.de \
    /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).