On 19/01/2013, at 2:11 PM, john skaller wrote: > > If I use the type int ^ (2 + 5 +2) at present the code doesn't work.
this does work if you get the @#$%^&*( syntax right: var x = (1,2,3,4,5,6,7,8,9); var z = x :>> (int ^ (2 + 5 + 2)); println$ z; fun f(x:5) => (case 1 of (2 + 5 + 2)) x; fun g(y:5):int => f y z; var a = f (1:>>5) z; var b = g (1:>>5); println$ a; println$ b; So here the function "g" is effectively an array representing the slice 3 .. 7. However you cannot retrieve it as an object, I guess because it's an indexing formula for a linear array, so there isn't actually any slice. The coercion here: var x = (1,2,3,4,5,6,7,8,9); var y = x :>> (int ^2*int^5*int^2); println$ y; reshapes the array, the coercion to z reshapes the index. The reshaped array requires two indexing operations to get an element: y . 1 . 1 Using the reshaped index that's ((case 1 of (2 + 5 + 2)) (case 1 of 5)) z; i.e. first select the middle 5 elements, then the second (index 1) element of that. Note you can do this: println$ z . ( (case 1 of 5) . (case 1 of (2 + 5 + 2))); but you cannot remove the parens after z . so this kind of reverse application isn't associative. Hmm. Note: with something like case 1 of 5 you'd like to write: case j of 5 where j was a variable (or expression) but you cannot. That's because those case things are literal constants. Indeed case 1 of (2 + 5 + 2) appears to be applied to case 1 of 5, but this is not so: it's a constructor not a function. Felix can wrap constructors into functions though. So if you want to make a "variable" case of type 5 here's how: match j with | 0 => case 0 of 5 | 1 => case 1 of 5 ... of course here j is an int. A quick way to do the above is: j :>> 5 which is basically j modulo 5 in "mathematical" notation. Note that here "modulo" is NOT an operator, just as in maths: j % 5 is an int j modulo 5 is a member of the cyclic group Z_5 At present in Felix, the type 5 is not Z_5, rather it's just the underlying set: there are NO operations on values of type 5. Of course it would be interesting to make 5 equal to Z_5, the clock with 5 digits, then we would have addition. The problem here is that 4 + 4 = 3 that is, there's no error from overflow. This has + and - as usual. The classic useful case is the formula for a determinant, where it is cool if the indices are modulo N, so when you increment them you just wrap around in the matrix. but it also means you can index past the end of an array and wrap around to the start, without realising your code was bugged, in the case you really didn't want that. Anyhow I am thinking to add the notation expression modulo base as a way to build modular numbers: base has to be a constant. It means, do the calculation of expression in Z_base. This is hard because whilst you can just do addition and multiplication and subtraction with ints and % base after, division doesn't work that way. -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only -- learn more at: http://p.sf.net/sfu/learnmore_122912 _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language