On 14/09/2013, at 5:21 PM, srean wrote: >> var x = (1,2,3); >> x . 1 = 42; >> assert x == (1,42,3); >> >> This can certainly be done as so: >> >> x = (x.0, 42, x.2); >> >> i.e. by replacing the whole value of x with a new value constructed >> to be the same as the old one except for the modified component. >> >> This mechanism has a name, its called "functional update" and it isn't >> well represented in Felix for arrays or tuples. > > Oh excellent ! it would be great to have such monolithic updates for > arrays and behind the curtains optimizations for in place > modifications when I dont look at the old array again.
Yes, it would, but you should read what I wrote more carefully: its not well represented in Felix. That is, there is no syntax for it, and there are no optimisations. With a couple of exceptions. For example: a,b,c = a,22,c should probably reduce to b = 22 eliminating the self assignments. > I have played > with this some in SISAL which is purely functional. A performance > problem I faced there is that SISAL's representation of 2d arrays is > array of arrays, so its expensive to access in column order. I have no idea which order is column order. But always one order is sequential and the other not. > > Please, take a look at Repa (Haskell's array library). I have not > used that one. They make heavy use of deforestations and fusions and Felix can do deforestation but not fusion. Fusion requires higher order polymorphism. Felix can do "a bit" of that, enough to define Monads, but not enough for fusion. >> Why is this SO totally cool? Because, apart from the store function >> in the library, all the rest of it is PURELY FUNCTIONAL. > > Lately I have been looking at an old concept (new to me) called I > structures that allow mutation but still maintains referential > transparency. Linear typing. A linear variable is one that is used exactly once. A trivial example: in any expression the temporary for any subexpression is linear. An example of how to leverage this: in C++ rvalue references do just that. void f (int &&x) { .. } here, x will only bind to an rvalue, which is a temporary, which can only be used once because of syntax. So it is acceptable to "suck" the value out of x, for example for a string implemented by a counter and pointer to array you can copy the pointer and NULL it out in the argument. In Felix there is an example of this "done manually" in the list library. A function such as "map" over a list is creates a reversed list, then reverses it "in place" and returns that. Its safe because the the list is owned by the function until after it is reversed and returned. >> >> The answer is obvious: the tuple case is the most general, arrays are >> a special case, so array indexing is just plain wrong. > > Heh! I have asked you about the possibility of "inductive" arrays, I > suspect thats where you are going. What I'm trying to do is simplify the compiler by trying to discover the most basic primitives. In any compiler you have code that handles the general case, and the a set of codes to handle special cases. The obvious example of this is code to add two integers: a + b but, it they're both literals, you can add them in the compiler instead. Other well known examples include doing a shift instead of a multiply by a power of two. So every "operation" in the compiler comprises a SET of routines, not just one. So it is good to minimise the number of operations. Its not always possible. For example Felix tuples are arrays if all values are the same type. So BTYP_tuple of t list can handle both (that's the Ocaml representation in the compiler]. Yet there is another type: BTYP_array of t * t for arrays. Why is this? Because of this example: var buffer : byte ^200_000_000; we really do NOT want a representation with 200 million terms. That would slow the compiler down a bit. -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99! 1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint 2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/22/13. http://pubads.g.doubleclick.net/gampad/clk?id=64545871&iu=/4140/ostg.clktrk _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language