Re: [Caml-list] equality operators in OCaml

2008-07-24 Thread Peng Zang
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


On Thursday 24 July 2008 06:32:36 pm Jon Harrop wrote:
> From: "Raj Bandyopadhyay" <[EMAIL PROTECTED]>
>
> > Hi OCaml folk
> >
> > I apologize if I've been asking too many questions on this list recently,
> > but I'm working on a heavy OCaml application and need help sometimes.
> >
> > I am having a disagreement with a colleague about how the equality
> > operators in OCaml work and am trying to resolve it conclusively.
> >
> > 1) I understand that the '==' operator is basically a pointer comparison
> > i.e. a==b true  iff a and b are the same entity. Is this true?
>
> There are some complications here. Firstly, NaN has multiple
> representations that may or may not be physically equal but is always
> structurally unequal to itself.


Yeah, that always seemed broken to me.  If two things are physically equal 
(they occupy the same memory space) it doesn't make sense for them to be 
structurally unequal (contain different content).  Personally, one of the 
first things I did is redefined (=) to fix this.

Peng
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFIiS8YfIRcEFL/JewRAnXqAKCAhHWGTHe6z58jRplmMmnNFgljUACfUhaJ
SQSWrxxpPpHqiJcFBcNlVsM=
=af4P
-END PGP SIGNATURE-

___
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] equality operators in OCaml

2008-07-24 Thread Jon Harrop

From: "Raj Bandyopadhyay" <[EMAIL PROTECTED]>

Hi OCaml folk

I apologize if I've been asking too many questions on this list recently, 
but I'm working on a heavy OCaml application and need help sometimes.


I am having a disagreement with a colleague about how the equality 
operators in OCaml work and am trying to resolve it conclusively.


1) I understand that the '==' operator is basically a pointer comparison 
i.e. a==b true  iff a and b are the same entity. Is this true?


There are some complications here. Firstly, NaN has multiple representations 
that may or may not be physically equal but is always structurally unequal 
to itself. Secondly, OCaml's implicit allocation can make "same entity" 
unclear, constant subexpressions (e.g. Some 3) may or may not be hoisted.


The only place I ever use == and != is when optimizing code in such a way 
that unexpected results from those functions result in slow but still 
correct code.


2) Where can I find the code implementing the '==' operator in the OCaml 
code?


Can you just compile it and look at the assembler? There are probably many 
different outputs depending upon the statically resolved types.


3) In case I do want to check object identity and can use the == operator, 
would it be faster to use '==', '=' or a match statement?


I believe the == operator would be fastest. More often that not, you want < 
and > so you end up augmenting your OCaml data structures with unique IDs 
anyway.


Note that physical equality does not even exist in SML and the designers of 
SML stand by that design decision. Perhaps it is best to avoid == in OCaml 
altogether.


Cheers,
Jon.

___
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] equality operators in OCaml

2008-07-24 Thread Vincent Hanquez
On Thu, Jul 24, 2008 at 02:27:51PM -0500, Raj Bandyopadhyay wrote:
> Hi OCaml folk
>
> I apologize if I've been asking too many questions on this list  
> recently, but I'm working on a heavy OCaml application and need help  
> sometimes.
>
> I am having a disagreement with a colleague about how the equality  
> operators in OCaml work and am trying to resolve it conclusively.
>
> 1) I understand that the '==' operator is basically a pointer comparison  
> i.e. a==b true  iff a and b are the same entity. Is this true?

yes. only valid for object that are in blocks though (int, char are not).
for object not in block, you end up with a simple =

> 2) Where can I find the code implementing the '==' operator in the OCaml  
> code?

byterun/compare.c : caml_equal which call compare_val with total=0 (which
means to not compare inside blocks)

> 3) In case I do want to check object identity and can use the ==  
> operator, would it be faster to use '==', '=' or a match statement?

i believe == is the fastest one. but that's just based on how the thing
works compare to the others compare, not on empirical benchs.

-- 
Vincent

___
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] OCaml and Matlab

2008-07-24 Thread Till Crueger
On Thu, 24 Jul 2008 11:23:27 +0200, Nicolas Pouillard  
<[EMAIL PROTECTED]> wrote:


So I am not at all surprised, that it won't work, because the 'a  
actually

is unbound. Was this maybe possible with older versions of the compiler,
or are there some workarounds, to get it working again?


That's a syntactic over the revised syntax of abstract types, now  
abstract

types are like in the original syntax:

  type mxArray;


Ok, that was also my first guess, that occured to me afterwards. So I  
changed it to normal abstract types and fixed the .mli file. However, the  
problem still remains, because the types are the same way in the actuall  
implementation file. So it seems like there is more at work here, because  
abstract types are not possible in .ml files, or are they?


--
Wenn du den Fnord nicht siehst, kann er dich auch nicht essen.

___
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] Array copying in OCaml

2008-07-24 Thread Adrien
You can compile with the -unsafe flag. If you're using arrays a lot,
it can easily speed your program by 50%. If your program is array
based, the speedup can be even more important.

Don't assume it could magically make your program behave in a weird
way. When you're trying to access an element which is outside the
bounds of the array, ocaml rises an exception. With the -unsafe flag,
no exception will be risen and you will have no chance to catch it.
Consequently if you're out of bounds, your programm will die. That's
why it is called "unsafe". If you're sure you won't be out of bounds
(or are not trying to catch any exception), you can safely use
-unsafe.

If you don't want to affect globally your program, you can also use
Array.unsafe_get or Arra.unsafe_set. I don't know the full list
though.


 ---

Adrien Nader

2008/7/24 Raj Bandyopadhyay <[EMAIL PROTECTED]>:
> Hi
>
> I have an application which copies a lot of (small) OCaml arrays using the
> Array library (Array.sub and Array.blit) functions. This is turning out to
> be extremely expensive.
>
> Is there any general way/trick to reduce the cost of this kind of operation?
> I haven't found a way not to copy as much, because the program semantics
> seems to demand it.
>
> Thanks
> Raj
>
> ___
> 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 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] equality operators in OCaml

2008-07-24 Thread Raj Bandyopadhyay

Hi OCaml folk

I apologize if I've been asking too many questions on this list 
recently, but I'm working on a heavy OCaml application and need help 
sometimes.


I am having a disagreement with a colleague about how the equality 
operators in OCaml work and am trying to resolve it conclusively.


1) I understand that the '==' operator is basically a pointer comparison 
i.e. a==b true  iff a and b are the same entity. Is this true?


2) Where can I find the code implementing the '==' operator in the OCaml 
code?


3) In case I do want to check object identity and can use the == 
operator, would it be faster to use '==', '=' or a match statement?


Thanks
Raj

___
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] Array copying in OCaml

2008-07-24 Thread Christophe TROESTLER
On Thu, 24 Jul 2008 11:31:50 -0500, Raj Bandyopadhyay wrote:
> 
> I have an application which copies a lot of (small) OCaml arrays
> using the Array library (Array.sub and Array.blit) functions. This
> is turning out to be extremely expensive.
> 
> Is there any general way/trick to reduce the cost of this kind of
> operation? I haven't found a way not to copy as much, because the
> program semantics seems to demand it.

That all depends on the set of operations you want to support on these
arrays.  For example, if all you want is access, concatenation and
slices, then an approach like the Rope library [1] may be envisioned.
What is the problem you want to solve?

Cheers,
C.

[1] http://ocaml-rope.sourceforge.net/

___
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] Array copying in OCaml

2008-07-24 Thread Dr. Thomas Fischbacher


Raj Bandyopadhyay wrote:


I have an application which copies a lot of (small) OCaml arrays using
the Array library (Array.sub and Array.blit) functions. This is turning
out to be extremely expensive.

Is there any general way/trick to reduce the cost of this kind of
operation? I haven't found a way not to copy as much, because the
program semantics seems to demand it.


Are you sure there is no way delaying copying to the latest possible
time (e.g. by introducing an intermediate array to which you copy data
and which you use until you know for sure that you will have to hold
on to your copy)?

--
best regards,
Thomas Fischbacher
[EMAIL PROTECTED]


___
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] Array copying in OCaml

2008-07-24 Thread Raj Bandyopadhyay

Hi

I have an application which copies a lot of (small) OCaml arrays using 
the Array library (Array.sub and Array.blit) functions. This is turning 
out to be extremely expensive.


Is there any general way/trick to reduce the cost of this kind of 
operation? I haven't found a way not to copy as much, because the 
program semantics seems to demand it.


Thanks
Raj

___
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] Memory statistics tool

2008-07-24 Thread Alain Frisch

Dr. Thomas Fischbacher wrote:

The OCaml manual gives no guarantee that Hashtbl.hash does not cons, so
I cannot assume this.


Indeed, Hashtbl.hash can cons, but this does not contradict my point: 
its result does not depend on the physical location of objects in memory

(if it did, it would be impossible to use this function at all).


Now, without that guarantee, there is a nasty race
condition in which the determination of the hash bucket causes objects
to move in memory.


Yes, objects can move in memory, but what is wrong with that? Their new 
hash value will remain the same.


-- Alain

___
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] Memory statistics tool

2008-07-24 Thread Dr. Thomas Fischbacher

Alain Frisch wrote:


As long as the data structure supports the polymorphic hash function, it
should work to simply use a regular hash table with the polymorphic hash
function and physical equality, as in:

module S = Hashtbl.Make(struct
  type t = Obj.t
  let hash = Hashtbl.hash
  let equal = (==)
end);;


Why? (I.e. I'm not convinced yet.)



The two functions (hash and equal) are invariant w.r.t. changes of
physical memory location of their arguments.


The OCaml manual gives no guarantee that Hashtbl.hash does not cons, so
I cannot assume this. Now, without that guarantee, there is a nasty race
condition in which the determination of the hash bucket causes objects
to move in memory. But still, we are safe, as we are just testing for
equality, and the hash bucket does not depend on the memory address,
but on the substructure of the hashed entity.

So, ok, you convinced me.


Anyway, it works now -- thanks to Dmitry's code, I can now do
things like...:

[EMAIL PROTECTED]:~/ocaml$ nsim_i

In [1]: ocaml.memory_footprint(ocaml.make_element("E",[3],3,1))
Out[1]: (154.0, 49.0, 5.0)

In [2]:

...and use the interactive Python toplevel of our micromagnetic
simulator "nmag" to find out how much memory is used by the OCaml
data structures under the hood. Excellent. Thanks, Dmitry!

--
best regards,
Thomas Fischbacher
[EMAIL PROTECTED]


___
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] CC 2009: abstracts due Oct 2

2008-07-24 Thread Oege . de . Moor
>>> abstracts - Oct 2, full papers - Oct 9 <<<

 CC 2009 
  International Conference on Compiler Construction
   March 22-29, York, United Kingdom 
 Invited Speaker: Vivek Sarkar (Rice University, US)
 Part of ETAPS 2009

http://www.cs.york.ac.uk/etaps09/Conf/conf.html#cc

CC is a premier forum for presenting research on compilers
in the broadest possible sense, including run-time techniques,
programming tools, domain-specific languages, novel language
constructs and so on. In recent years CC has seen a healthy
increase in the number of submissions, in line with its broad
outlook; its typical acceptance rate is 20-25%. CC is part of 
ETAPS, and this year it is held in York (UK), March 22-29 2009.

The program committee would particularly welcome
submissions from

researchers in functional programming  

on any topic relating to

compilation and analysis of caml, or via caml

Abstracts are due on October 2, and the deadline for
full paper submission is October 9.

Prospective authors are welcome to contact the program
chairs, Michael Schwartzbach ([EMAIL PROTECTED]) and Oege de Moor 
([EMAIL PROTECTED]) with any queries they might have.





___
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] Memory statistics tool

2008-07-24 Thread Alain Frisch

Dr. Thomas Fischbacher wrote:

Alain Frisch wrote:

As long as the data structure supports the polymorphic hash function, it
should work to simply use a regular hash table with the polymorphic hash
function and physical equality, as in:

module S = Hashtbl.Make(struct
   type t = Obj.t
   let hash = Hashtbl.hash
   let equal = (==)
end);;


Why? (I.e. I'm not convinced yet.)


The two functions (hash and equal) are invariant w.r.t. changes of 
physical memory location of their arguments.


-- Alain

___
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] Memory statistics tool

2008-07-24 Thread Dr. Thomas Fischbacher

Alain Frisch wrote:


Many thanks! I just had a glance at it, but it seems to be just how one
would have to approach such a problem. (The issue with hash-based
approaches to find previously visited substructures is that during
traversal, a GC may occur. Now I just assume that this may involve
relocation and heap compaction in OCaml. The problem then is that
OCaml does not properly support what would be known as eq hash tables
in Lisp.)



As long as the data structure supports the polymorphic hash function, it
should work to simply use a regular hash table with the polymorphic hash
function and physical equality, as in:

module S = Hashtbl.Make(struct
   type t = Obj.t
   let hash = Hashtbl.hash
   let equal = (==)
end);;


Why? (I.e. I'm not convinced yet.)

--
best regards,
Thomas Fischbacher
[EMAIL PROTECTED]



___
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] OCaml and Matlab

2008-07-24 Thread Nicolas Pouillard
Excerpts from Till Crueger's message of Thu Jul 24 10:47:51 +0200 2008:
> Hi,
> 
> I am currently trying to get OCaml and Matlab to work together. I found
> OCamlMex on the Caml-Hump
> (http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=400).
> However when I try to compile it, I get an error:
> 
> ocamlc.opt -c -pp "camlp4r " -I /usr/lib64/ocaml/camlp4 mex.mli
> File "mex.mli", line 235, characters 15-17:
> Unbound type parameter 'a
> make[2]: *** [mex.cmi] Fehler 2
> make[2]: Leaving directory `/home/till/ocamlmex-2.0.1/src'
> make[1]: *** [byte-code-library] Fehler 2
> make[1]: Leaving directory `/home/till/ocamlmex-2.0.1/src'
> make: *** [all] Fehler 2
> 
> The line mentioned in the error looks like this:
> 
> type mxArray = 'a;
> (** The basic type for all the external data inside Matlab : a mxArray
> can be a numeric array, a cell array, a struct array, or other kind of
> data see mxClassID *)
> 
> So I am not at all surprised, that it won't work, because the 'a actually
> is unbound. Was this maybe possible with older versions of the compiler,
> or are there some workarounds, to get it working again?

That's a syntactic over the revised syntax of abstract types, now abstract
types are like in the original syntax:

  type mxArray;

-- 
Nicolas Pouillard aka Ertai


signature.asc
Description: PGP signature
___
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 and Matlab

2008-07-24 Thread crueger
Hi,

I am currently trying to get OCaml and Matlab to work together. I found
OCamlMex on the Caml-Hump
(http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=400).
However when I try to compile it, I get an error:

ocamlc.opt -c -pp "camlp4r " -I /usr/lib64/ocaml/camlp4 mex.mli
File "mex.mli", line 235, characters 15-17:
Unbound type parameter 'a
make[2]: *** [mex.cmi] Fehler 2
make[2]: Leaving directory `/home/till/ocamlmex-2.0.1/src'
make[1]: *** [byte-code-library] Fehler 2
make[1]: Leaving directory `/home/till/ocamlmex-2.0.1/src'
make: *** [all] Fehler 2

The line mentioned in the error looks like this:

type mxArray = 'a;
(** The basic type for all the external data inside Matlab : a mxArray
can be a numeric array, a cell array, a struct array, or other kind of
data see mxClassID *)

So I am not at all surprised, that it won't work, because the 'a actually
is unbound. Was this maybe possible with older versions of the compiler,
or are there some workarounds, to get it working again?

Do you know of any other ways to get OCaml and Matlab to communicate?
Another way I can think of is to use the OCaml <-> Java interface and the
Matlab <-> Java interface, but this would get nasty, and I'd have to write
the wrappers myself.

So if you know anything on this topic, please let me know.

Thanks,
  Till

___
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