briand | 1 Apr 06:00 2004

Re: examples of heterogenous collections (containers ?)

>>>>> "skaller" == skaller  <skaller <at> users.sourceforge.net> writes:

  skaller> You are thinking about this problem *backwards*! :)

Well that's why it's giving me so much trouble. :-)

  skaller> The cast will always work if the object has a method named
  skaller> 'f' which when invoked with no arguments returns unit.
  skaller> Obviously, because Ocaml is wonderful, your cast will fail
  skaller> on objects without a suitable 'f' method.

I LIKE IT.  No inheritance required.  Objects which have the same
method with the same signature work "automagically".

  skaller> The solution is to use a factory function in a single
  skaller> module, and return an abstraction of the class type you
  skaller> wish to deal with.

I'm not sure I followed that, can you expand ?

For future readers of the list here and appropriate example.  It turns
out I was silly and never even bothered to look in the _manual_ of all
places.  I looked everywhere else.  This is covered in the section
called "Using Coercions", go figure.

Anyway, enough blather, here's the example :

class elt = object
  method f x = 2 * x
end
(Continue reading)

briand | 1 Apr 06:08 2004

exene and ocaml ?


I'm new to ML and have been wondering the ML landscape looking for
nifty ML related tidbits when I ran across exene (http://people.cs.uchicago.edu/~jhr/eXene/).

Has anyone in the ocaml community ever even considered porting this to
ocaml ?  I noticed that it requires threading.  Does anyone have an
opinion as whether ocaml's threads would be compatible with such a
system ?

Thread based gui implementations are the way to go (aren't they ?)

I have been working with labgtk and I've noticed that it suffers from
the underlying limitations of gtk, i.e. it's pure event based.  So
consider an interactive routine to draw a line:

event mouse_button:  draw_line with mouse_button event
event_key: draw_line with key_event
event_motion: draw_line wtih motion_event
...

draw_line event_variant :

dispatch on event

  do something with a GLOBAL variable (or module local ?) !

  pass state information back to main routine to signal change of
  state, e.g. escape key has stopped line drawing mode

YUCH.
(Continue reading)

Shivkumar Chandrasekaran | 1 Apr 06:48 2004
Picon

Weak pointers and Gc.finalise

I just noticed that if the only reference to a bigarray is in a Weak.t 
array, and if there is a finalisation function set on the bigarray, 
then that finalisation function is not necessarily called when the 
entry in the Weak.t array is set to None. Rather it is potentially 
called *much* later.

I am assuming that this is the right behaviour.

My question is, can I get the finalisation function to be called when 
the weak pointer is being set to None?

(Side note: I am trying to avoid Marshaling the Bigarray unless it is 
going to be garbage-collected. But if I cannot detect that, then I have 
to always Marshal it whenever its entries change, which is very 
inefficient.)

Thanks,

--shiv--

-------------------
To unsubscribe, mail caml-list-request <at> 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

Shivkumar Chandrasekaran | 1 Apr 06:59 2004
Picon

Bigarray.Genarray.map_file

When I use the map_file function in Bigarray module I need to pass a 
Unix file_descriptor. Who is in charge of closing it? Is it done 
automatically when the Bigarray is garbage collected? Thanks,

--shiv--

-------------------
To unsubscribe, mail caml-list-request <at> 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

skaller | 1 Apr 09:20 2004
Picon
Picon

Re: examples of heterogenous collections (containers ?)

On Thu, 2004-04-01 at 14:00, briand <at> aracnet.com wrote:
> >>>>> "skaller" == skaller  <skaller <at> users.sourceforge.net> writes:
> 
>   skaller> You are thinking about this problem *backwards*! :)
> 
> Well that's why it's giving me so much trouble. :-)

:-)

> I LIKE IT.  No inheritance required. 

you can write (inside a class definition):

	inherit X;

which is just a safe form of 'macro' that pulls in the methods
of X to save you keyboarding. In the OO world this is known
as 'implementation inheritance'.

>   skaller> The solution is to use a factory function in a single
>   skaller> module, and return an abstraction of the class type you
>   skaller> wish to deal with.
> 
> I'm not sure I followed that, can you expand ?

Yeah, I'll explain below ..

> Anyway, enough blather, here's the example :
> 
> class elt = object
(Continue reading)

Ville-Pertti Keinonen | 1 Apr 09:25 2004

Re: exene and ocaml ?


On Apr 1, 2004, at 7:08 AM, briand <at> aracnet.com wrote:

> Has anyone in the ocaml community ever even considered porting this to
> ocaml ?  I noticed that it requires threading.  Does anyone have an
> opinion as whether ocaml's threads would be compatible with such a
> system ?

It seems eXene doesn't depend on first-class continuations directly, so 
a port may be possible.  CML threads are several orders of magnitude 
more lightweight than OCaml threads and are garbage collected (they 
disappear if they are blocked in a state that they could not wake up 
from), so a direct port is IMHO probably not worth attempting.

> Thread based gui implementations are the way to go (aren't they ?)

It's one way to do things, but by no means the only way.  A 
single-threaded event model works reasonably well for GUIs, especially 
in most current languages where threads are needlessly expensive.

> Consider the much more elegant and functional implementation:
>
> new line = draw_line event_stream
>
> draw_line event_stream
>   consume events until done
>   return tuple (success/fail, line object)

How is this approach dependent on threads?  I don't know about lablgtk, 
but something like the above is generally possible by recursively 
(Continue reading)

skaller | 1 Apr 10:19 2004
Picon
Picon

Re: exene and ocaml ?

On Thu, 2004-04-01 at 17:25, Ville-Pertti Keinonen wrote:
> On Apr 1, 2004, at 7:08 AM, briand <at> aracnet.com wrote:
> 
> > Has anyone in the ocaml community ever even considered porting this to
> > ocaml ?  

> > Thread based gui implementations are the way to go (aren't they ?)

You may be interested in Felix. Control inversion is a central
concept, that is, translating a program that reads events
into an event driven one, automatically. Felix threads
are cooperatively multi-tasked, the system supports
millions of threads and fast O(1) switching is possible.

At present, Felix generates C++, however the control inversion
mechanism isn't language specific, all it requires is classes with
methods, and some kind of switch statement. Ocaml has both,
so retargetting to Ocaml may be possible. The back end isn't
fully decoupled from the front end yet though, and the lack
of a goto in Ocaml may impact performance. On the other hand
the Ocaml GC is bound to be superior to the naive implementation
I provide.

> It's one way to do things, but by no means the only way.  A 
> single-threaded event model works reasonably well for GUIs, especially 
> in most current languages where threads are needlessly expensive.

Event driven programming model requires manual
state management. In losing the stack, the most powerful
structuring tool available to the progammer is lost,
(Continue reading)

Correnson Loïc | 1 Apr 10:43 2004
Picon

Re: What's wrong with win32?

More over, it works very well on W2K with the previous release (ocaml-3.06).
It seems that there is a regression (bug submitted yet).
    LC.

-------------------
To unsubscribe, mail caml-list-request <at> 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

Richard Cole | 1 Apr 11:04 2004
Picon
Picon

Indeterminate Initialization: Is it a Bug?

Hi,

There seems to be a difference in initialization behaviour using the 
native compiler depending on whether a module contains non "external" 
calls. Let me give an example:

#!/bin/bash
rm -f test_funky.ml funky.ml ml_funky.c *funky*.cm* *funky*.a *funky*.so

echo '
  Printf.fprintf stderr "Test.Init\n"; flush stderr ;;
  open Funky ;;
  funky 4 ;;
' > test_funky.ml

echo '
  #include <caml/mlvalues.h>
  #include <caml/memory.h>
  #include <stdio.h>

  value ml_funky(value v)
  {
    CAMLparam1(v);
    int i = Int_val(v) + 1;
    fprintf(stderr, "ML_FUNKY!\n"); fflush(stderr);
    CAMLreturn(Val_int(i));
  };
' > ml_funky.c

echo '
(Continue reading)

skaller | 1 Apr 11:15 2004
Picon
Picon

Re: Re: Ocamlgraph build error

[Patched Ocamlgraph so it works on 32 bit machine]
-------------------
module Elt = struct 
  type t = int 
  let compare = compare 
  let hash = Hashtbl.hash 
  let equal = (=)
end

;;

module MyGraph = Graph.Imperative.Digraph.Concrete(Elt)
;;
let check() =
  let g = MyGraph.create () in
  MyGraph.add_vertex g 1;
  MyGraph.add_vertex g 2;
  MyGraph.add_vertex g 3;
  MyGraph.add_vertex g 4;
  MyGraph.add_vertex g 5;
  MyGraph.add_edge g 1 2;
  MyGraph.add_edge g 2 3;
  print_endline "Graph constructed"
;;

print_endline "Try using graph module";;
check();;

---------------------
This works fine as per instructions:
(Continue reading)


Gmane