Re: [Caml-list] Re: Being aware of memory overuse

2010-02-10 Thread Goswin von Brederlow
Sylvain Le Gall sylv...@le-gall.net writes:

 On 05-02-2010, David Rajchenbach-Teller david.tel...@mlstate.com wrote:
Dear list,
  I'm writing some code that needs to be able to cope nicely with
  memory exhaustion. That is, it should be able to detect at some point
  if it is getting close to exhausting memory, and take the necessary
  course of action (e.g. bailing out nicely). I'm wondering what's the
  best way of doing this. I've been thinking about installing a
  [Gc.alarm] and checking [Gc.free_words], [Gc.free_blocks],
  [Gc.largest_free] just after each major cycle, but I'm wondering if
  it's the best technique.

 Any suggestion?


 I worked on this subject, for a tool that need to use as much memory as
 possible. I started by trying to use Gc module. I ended by reading
 /proc/meminfo and getting/checking data from there. It is fast, simple
 and very precise. In particular, it can take into account other
 processes that take memory.

 Regards,
 Sylvain Le Gall

I always wanted to have kernel spport for this. Some way for aplication
to tell the kernel about freeable memory and for the kernel to request
some memory to be freeed instead of swapping it out.

This would be usefull for e.g. a web browser that caches images and
rendered pages in memory for quick redraws and many other applications.

MfG
Goswin

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] Preventing values from escaping a context

2010-02-10 Thread Goswin von Brederlow
Rich Neswold rich.nesw...@gmail.com writes:

 On Tue, Feb 9, 2010 at 12:45 PM, Tiphaine Turpin tiphaine.tur...@irisa.fr
 wrote:

 Here is an adaptation of your example.


 Thank you! I'll experiment with your example to see if I can use it (like you
 said, it may be too complicated to add to the API.) Regardless, it was an
 interesting lesson and taught me a little more about the language.

 Thanks again,

Why not make the context a custom block with finalizer? The finalizer
then frees the resources. If the context escapes then it remains alive
and the finalizer will not be called any time soon. Only when it is no
longer reachable. That would also allow someone to create a context and
use it for a number of operations before forgeting it.

The drawback is that the finalizer will only be called when the GC runs
at some later time. If you need the resources to be freed right there
then it won't help.

MfG
Goswin

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] The need to specify 'rec' in a recursive function defintion

2010-02-10 Thread Francois Maurel


 # let y = z z ;;
 val y : (('_a - '_b) - '_a - '_b) - '_a - '_b = fun

 Can anyone get rid of the pesky underscores in the type of y above, so
 that it becomes truly polymorphic?


Eta expansion does it...

# let y x = z z x;;
val y : (('a - 'b) - 'a - 'b) - 'a - 'b = fun

Regards,
François
___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] The need to specify 'rec' in a recursive function defintion

2010-02-10 Thread rossberg
Andrej Bauer andrej.ba...@andrej.com wrote:

 What Gerd probably meant was that the usual untyped lambda-calculus
 definition of y, which gets us recursion out of nothing isn't typeable
 because self-application requires unrestricted recursive types.

Fortunately, even that is not quite correct: Y is perfectly typable in
plain ML, you just need to introduce the recursive type it employs
explicitly:

type 'a fix = Fix of ('a fix - 'a)
let fix f = let z = fun (Fix g' as g) x - f (g' g) x in z (Fix z)

Now, for example:

let fac = fix (fun fac n - if n = 0 then 1 else n * fac (n-1))
let n = fac 7

Best,
/Andreas

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] The need to specify 'rec' in a recursive function defintion

2010-02-10 Thread rossberg
Jon Harrop:
 On Tuesday 09 February 2010 22:01:03 Gerd Stolpmann wrote:
 In the ML community it is consensus that a recursive function is a total
 different thing than a non-recursive function...

 Note that Standard ML does this differently to CAML/OCaml.

Not quite -- SML simply defines fun f x = ... to be an abbreviation for
val rec f = fn x = 

/Andreas

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] Re: Being aware of memory overuse

2010-02-10 Thread Dario Teixeira
Hi,

 I always wanted to have kernel spport for this. Some way for aplication
 to tell the kernel about freeable memory and for the kernel to request
 some memory to be freeed instead of swapping it out.

If I recall correctly, there was an Lwn.net article reporting a lkml
(the Linux kernel mailing list) discussion on that subject.  One of
the proposals was for the kernel to send processes a signal (SIGFREE?)
requesting they free up memory (by running a major GC, for example)
whenever memory was running low.  In theory this could in some cases
avoid the invocation of the draconian OOM killer.

Question: just how effective such a feature would be in the Ocaml case?

Best regards,
Dario Teixeira



 

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


[Caml-list] [Ann] OCamlSpotter 1.1rc2 for OCaml 3.11.2

2010-02-10 Thread Jun Furuse
Hi Caml-list,

I have updated OCamlSpotter, a compiler enhancement for source code browsing,
to version 1.1rc2, which is aimed for OCaml 3.11.2 and some enhancements
since its first release.

OCamlSpotter is a tool which finds definition places of various names
(identifiers,
type names, modules, etc) in OCaml programs automatically for you.
The original OCaml's -annot option provides the same sort of functionality but
OCamlSpotter provides much more powerful browsing: it can find
definitions hidden
in the deep nested module aliases and functor applications.

 - The -annot option of ocamlc and ocamlopt is extended and creates
  module.spot files (module.spit for .mli), which record the location
  information of the names defined and used in the module.

 - A small application ocamlspot provides automatic where-about spotting
  of the definition of the name you are interested in, using module.spot files
  created by the patched compilers.

 - ocamlspot.el provides interactive ocaml-spotting of definition
  locations in emacs.

 - Interfaces for other editors such as vi could be built easily, if you want.

This release of OCamlSpotter is quite near to 1.1, but still in a RC state.
It will become the real 1.1 after 1 or 2 weeks with minimum bug fixes.

Further information and download is available at:

http://jun.furuse.info/hacks/ocamlspotter

Happy hacking.
Jun

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


[Caml-list] Re: Being aware of memory overuse

2010-02-10 Thread Sylvain Le Gall
On 10-02-2010, Dario Teixeira darioteixe...@yahoo.com wrote:
 Hi,

 I always wanted to have kernel spport for this. Some way for aplication
 to tell the kernel about freeable memory and for the kernel to request
 some memory to be freeed instead of swapping it out.

 If I recall correctly, there was an Lwn.net article reporting a lkml
 (the Linux kernel mailing list) discussion on that subject.  One of
 the proposals was for the kernel to send processes a signal (SIGFREE?)
 requesting they free up memory (by running a major GC, for example)
 whenever memory was running low.  In theory this could in some cases
 avoid the invocation of the draconian OOM killer.

 Question: just how effective such a feature would be in the Ocaml case?



I forgot to tell about other paths I have followed: setrlimit/getrlimit.
There are limits like RLIMIT_DATA, RLIMIT_RSS et al (CPU...). setrlimit
limits memory by generating ENOMEM when limits are reached and getrlimit
should give information about the current level of use of these limits.
Unfortunately, the memory consumption I get with getrlimit is not
accurate (in fact not updated).

I have OCaml bindings for this, I should published in a near future. 

Regards,
Sylvain Le Gall

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] An extended comparative study of language support for generic programming

2010-02-10 Thread Jon Harrop
On Wednesday 10 February 2010 23:00:44 Raoul Duke wrote:
  http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.110.122rep=rep1
 type=pdf
 
 :-)

 http://groups.google.com/group/comp.lang.functional/browse_thread/thread/d6
54fedd6efdf753/3ee82770d5e79402#3ee82770d5e79402

See my response there:

http://groups.google.com/group/comp.lang.functional/msg/2cb15a6281087b04

:-)

I was wondering if anyone here was familiar with this work and/or had anything 
to say about their OCaml solutions and discussion?

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] llvm?

2010-02-10 Thread Jon Harrop
On Wednesday 10 February 2010 22:51:33 Raoul Duke wrote:
 hi,

 any news about / anybody working on ocaml-on-llvm?

I don't believe anyone is working on porting OCaml to LLVM.

The nearest work is probably my own HLVM project which reached a major 
milestone recently and is now capable of high-performance parallel 
programming:

  http://flyingfrogblog.blogspot.com/2010/01/naive-parallelism-with-hlvm.html

From the point of view of an OCaml programmer, HLVM is a DSL that drops 
various features from OCaml (e.g. polymorphic recursion) in order to provide 
easily-obtained, predictable and high performance.

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] Re: The need to specify 'rec' in a recursive function defintion

2010-02-10 Thread Jon Harrop
On Wednesday 10 February 2010 22:25:44 Till Varoquaux wrote:
 Some (including me) would even argue that it is sad that type
 definitions don't use rec.

Agreed. Less useful than rec on function definitions but that would still be 
useful sometimes.

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


[Caml-list] Ocaml, Objective-c, and XCode

2010-02-10 Thread Andrew Webb
Hi there,

I have a few questions relating to using Ocaml with objective-c for anyone who 
programs on a Mac. I am aware that there aren't any real bindings between ocaml 
and objective-c/cocoa, so I am investigating rolling my own. So:

1) Does anyone have experience in interfacing ocaml and objc? Is it difficult?
2) Does anyone have a small example project that does mix these two languages? 
I have looked at unison, but it is too big for me to get my head around. I am 
thinking more on the scale of the ubiquitous Currency Converter...
3) Does anyone who is mixing these languages use Xcode to do so? If so, what 
steps do you need to go through to set that up?

A big thanks to anyone who can answer (some of) these questions. I am trying to 
decide whether to use haskell or ocaml for my next cocoa application, as these 
are the two languages I am most comfortable. I have recently found an excellent 
description of how to do this using haskell 
(http://tscheff.blogspot.com/2010/02/currync-converter-using-haskell-with.html) 
and was wondering if there were such resources for ocaml.

Thanks,
Andrew

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


[Caml-list] Re: The need to specify 'rec' in a recursive function defintion

2010-02-10 Thread oleg

Fortunately OCaml is (much more) than simply-typed lambda
calculus. Almost any feature of OCaml -- recursive data types,
recursive types, reference cells, mutable records, exceptions,
objects, recursive modules and polymorphic variants -- can be used to
express the fixpoint combinator. Sometimes there is more than one way
to use the same feature to express the fixpoint combinator. The more
and less known ways of expressing fix are collected in the following
document:

http://okmij.org/ftp/ML/fixpoints.ml

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs