From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 41F8ABBAF for ; Thu, 24 Dec 2009 16:37:49 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnsBADkZM0vUnwdkkGdsb2JhbACCGZlAAQEJCQwHEwS5EIQzBA X-IronPort-AV: E=Sophos;i="4.47,449,1257116400"; d="scan'208";a="40520280" Received: from relay.pcl-ipout02.plus.net ([212.159.7.100]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 24 Dec 2009 16:37:48 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmcFAKcZM0tUXebi/2dsb2JhbACCGdMLhDME Received: from relay03.plus.net ([84.93.230.226]) by relay.pcl-ipout02.plus.net with ESMTP; 24 Dec 2009 15:37:48 +0000 Received: from [87.114.35.173] (helo=leper.local) by relay03.plus.net with esmtp (Exim) id 1NNpl6-0004iC-0I for caml-list@yquem.inria.fr; Thu, 24 Dec 2009 15:37:48 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: multicore wish Date: Thu, 24 Dec 2009 16:51:58 +0000 User-Agent: KMail/1.9.9 References: <4B2D2BC1.6020204@msu.edu> <200912221920.29008.jon@ffconsultancy.com> <87vdfw5y1h.fsf@frosties.localdomain> In-Reply-To: <87vdfw5y1h.fsf@frosties.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200912241651.58909.jon@ffconsultancy.com> X-Plusnet-Relay: 515f0126f8c246ac01a1975bbbfdd071 X-Spam: no; 0.00; ocaml:01 pointers:01 ocaml:01 pointers:01 structs:01 pointer:01 pointer:01 arrays:01 mutable:01 val:01 val:01 structs:01 implements:01 struct:01 indirection:01 On Thursday 24 December 2009 12:58:18 Goswin von Brederlow wrote: > Jon Harrop writes: > > On Tuesday 22 December 2009 18:02:32 Edgar Friendly wrote: > >> On 12/22/2009 01:12 PM, Jon Harrop wrote: > >> > On Tuesday 22 December 2009 13:09:27 Goswin von Brederlow wrote: > >> >> The advantage with ocaml though is that you never have pointers into > >> >> a structure. Makes thinks a lot simpler for the GC and avoids large > >> >> overheads in memory. > >> > > >> > I don't understand what you mean by OCaml "never has pointers into a > >> > structure". Half the problem with OCaml is that OCaml almost always > >> > uses pointers and the programmer has no choice, e.g. for complex > >> > numbers. > >> > >> I think he means that ocaml structs (records, tuples) will only ever > >> have pointers pointing to their beginning - you can't have a pointer to > >> somewhere in the middle of a structure. > > Exactly. > > > If so then I do not understand the relevance. You cannot have pointers > > into a structure in F# or HLVM either... > > If you have an array a of (int * int) then in ocaml a is an array of > pointers to tuples. a.(5) is a pointer to the 6th tuple. Yes. > You said that in F# the array will be really an array of tuples. Then > a.(5) will be a pointer into the array at the position where the 6th > tuple is. No. The expression a.(5) loads all fields of the value type. For example, if it were an array of complex number then a.(5) would load the real and imaginary parts. > That means as long as a.(5) is reachable the full array has to remain > allocated or the GC has to recognise that only one (a few) items of an > array are reachable and copy them before freeing the array. The GC > also needs a way to find the begining of an allocated block from a > pointer into the block. Which means extra overhead in both memory and > time. > > Another think is that tuples are immutable but arrays are mutable. In > ocaml you get this nice behaviour: > > # let a = Array.init 5 (fun x -> (x,x));; > val a : (int * int) array = [|(0, 0); (1, 1); (2, 2); (3, 3); (4, 4)|] > # let x = a.(1);; > val x : int * int = (1, 1) > # a.(1) <- (2,2);; > - : unit = () > # x;; > - : int * int = (1, 1) > > In F# you would get (2,2) for your fast sortable array. A different > semantic. No. Even if F# represented tuples as structs (which it does not, unfortunately) you would still get the same result as you do in OCaml. HLVM already implements tuples as structs and your example works exactly as the OCaml does: # let xs = create(6, (1, 1)) in let x = xs.(1) in xs.(1) <- (2, 2); x;; - : `Struct[`Int; `Int] = (1, 1) The only difference is that HLVM unboxes the pairs in the array so the heap contains only a single pointer and accessing a pair requires only one indirection. -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e