Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## felix-language — Design of t he Felix programming language

You can subscribe to this list here.

2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 Jan Feb Mar Apr May Jun Jul (1) Aug Sep (4) Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep (1) Oct Nov Dec Jan Feb Mar Apr (6) May (4) Jun (2) Jul Aug Sep Oct (3) Nov Dec Jan Feb (1) Mar (14) Apr (71) May (93) Jun (17) Jul (62) Aug (25) Sep (42) Oct (43) Nov (51) Dec (70) Jan (15) Feb (20) Mar (1) Apr (29) May (18) Jun (27) Jul (71) Aug (114) Sep (89) Oct (177) Nov (107) Dec (54) Jan (165) Feb (111) Mar (138) Apr (99) May (78) Jun (85) Jul (104) Aug (97) Sep (276) Oct (313) Nov (65) Dec (35) Jan (21) Feb (143) Mar (136) Apr (174) May (99) Jun (11) Jul (225) Aug (54) Sep (118) Oct (44) Nov (31) Dec (9) Jan (1) Feb (1) Mar (21) Apr May (23) Jun Jul (3) Aug (4) Sep (5) Oct Nov (1) Dec Jan (1) Feb (7) Mar (38) Apr (75) May (12) Jun (34) Jul Aug (6) Sep (20) Oct Nov (13) Dec (1) Jan (26) Feb Mar Apr (2) May Jun Jul Aug (1) Sep (3) Oct (140) Nov (88) Dec (63) Jan (41) Feb (35) Mar (31) Apr (20) May (4) Jun Jul Aug Sep Oct (11) Nov (30) Dec (8) Jan (28) Feb (35) Mar (27) Apr (55) May (57) Jun (23) Jul (18) Aug (86) Sep (20) Oct (16) Nov (65) Dec (59) Jan (65) Feb (77) Mar (51) Apr (16) May (46) Jun (19) Jul (18) Aug (4) Sep (18) Oct (18) Nov (25) Dec (38) Jan (71) Feb (48) Mar (32) Apr (6) May (17) Jun (2) Jul (1) Aug (82) Sep (40) Oct (2) Nov (8) Dec (5) Jan (4) Feb (12) Mar (23) Apr (12) May Jun Jul Aug Sep Oct Nov Dec

Showing results of 5880

1 2 3 .. 236 > >> (Page 1 of 236)
 Re: [Felix-language] code generator change From: john skaller - 2015-04-29 11:24:27 On 29/04/2015, at 5:52 PM, john skaller wrote: Scrub that.. too hard to make it work right. We would have to spell it _tt3 because of C's idiot macros. [offsetof in particular but others I defined myself for handling variants] > I am changing the code generator to use templates for some types. > This is a bit experimental. You will need to do this if you don't > want to do a complete rebuild: > > cp src/rtl/flx_compiler_support_bodies.hpp build/release/share/lib/rtl/ > > This change replaces a generated tuple for sizes 2,3,4,5 with > a template, provided the type isn't recursive. For example: > > //TYPE 65766: int * string * int > typedef _tt3_tt65766; -- john skaller skaller@... http://felix-lang.org 
 [Felix-language] code generator change From: john skaller - 2015-04-29 07:53:25 I am changing the code generator to use templates for some types. This is a bit experimental. You will need to do this if you don't want to do a complete rebuild: cp src/rtl/flx_compiler_support_bodies.hpp build/release/share/lib/rtl/ This change replaces a generated tuple for sizes 2,3,4,5 with a template, provided the type isn't recursive. For example: //TYPE 65766: int * string * int typedef _tt3_tt65766; -- john skaller skaller@... http://felix-lang.org 
 Re: [Felix-language] function product From: john skaller - 2015-04-29 05:47:40 On 28/04/2015, at 11:36 PM, john skaller wrote: > I'm giving up: I'm defining it directly in the compiler. This now works: //////////////// fun f (x:int) : int => x + 1; fun g (x:int): string => x.str+"!"; fun h (x:double) :string => x.str+"!"; var fgx = \prod (f,g,h); println$fgx (1,2,3.1); ///////////// Result: (2, 2!, 3.1!) I still have to do dup, sums, etc. \prod (f,g) is the same as f \times g. However var tup = f,g,h; var fgh = \prod tup; works with the new code, the only way to write that with \times and \otimes is tup.0 \otimes (tup.1 \times tup.2) -- john skaller skaller@... http://felix-lang.org   Re: [Felix-language] function product From: john skaller - 2015-04-28 13:37:27 On 28/04/2015, at 11:26 AM, john skaller wrote: > However \prod (f,g,h) still can't be defined, i have ravel (f,g,h) in the > library for up to 5 cases. I'm giving up: I'm defining it directly in the compiler. And sum too. Now, to get the mediating morphism of a product, for many n, we note that = x.dup2.( \prod (f,g) ) So the aim is to now define: fun dup[N,T] (x:T):T^N => x,x,x,...,x // n times which is just an array length N filled with x's... I guess that is already in the library under another name. (as an array constructor?) The function is also called \diag printed as a \delta. The sum version is called \nabla, it takes n x's and produces a single x. -- john skaller skaller@... http://felix-lang.org   [Felix-language] function product From: john skaller - 2015-04-28 01:29:06 This works: fun \times[u1,u2,r1,r2] (f1:u1->r1,f2:u2->r2) : u1 * u2 -> r1 * r2 => fun (x1:u1,x2:u2) => f1 x1, f2 x2; fun \otimes[D1,C1,D,C] (f1:(D1->C1), f:(D->C)) : (D1 ** D) -> (C1 ** C) => fun (a:D1 ** D) : C1 ** C => match a with | (x1,,x) => f1 x1,,f x endmatch ; fun i2s (x:int)=>x.str+"!"; fun i2i (x:int)=>x+1; var fs = i2s,i2i,i2s,i2s; var r = fs.0 \otimes fs.1 \otimes (fs.2 \times fs.3); println$ r (1,2,3,4); But it isn't pretty. The final \times is requires as the ground case (and need parens because of grammar issues, \otimes is right assoc). However \prod (f,g,h) still can't be defined, i have ravel (f,g,h) in the library for up to 5 cases. -- john skaller skaller@... http://felix-lang.org 
 Re: [Felix-language] [felix] mathmode From: john skaller - 2015-04-26 08:59:15 This now works: println$$$\sum (1,2,3,4)$$ ; println$ \prod (1,2,3,4); println$\sum (1,2,3,4).darray; println$ \prod (1,2,3,4).darray; println$\sum (1,2,3,4).list; println$ \prod (1,2,3,4).list; There are two overloads each: one for arrays and one for streamables. The above are all arrays (including list). If the array overload won't go, the streamable overload can be used, however it requires the value type to be specified like \sum[int] ... Of course \sum and \prod give TeX Sigma and Pi symbols :) I will call these pure sums because they take a whole data structure as an argument. Next I will try to figure out how to do indexed sums. These are sums over a formula with an index variable and so require the variable initial and final values be specified. In TeX the notation is \sum_{i=0}^{n-1} (formula (i)) This won't quite work for Felix. Instead we have to specify the type of the index, and, figure some way to specify the limits. As usual programming languages are highly ambiguous but maths is the over the top extremely ambiguous (just to confuse everyone!) You will of course note these are just special cases of folds. They're convenient in some limited circumstances the most important of which is probably showing how beautiful Felix is :) -- john skaller skaller@... http://felix-lang.org 
 [Felix-language] mathmode From: john skaller - 2015-04-25 23:16:58 I'm changing the display rules for mathmode. First, { } will not be displayed in mathmode. Use \{ \} if you want to see something. Second, a Felix identifier will usually emit \mathtt{identifier} which will cause it to be typeset in teletype font, similar to the usual program text font I hope. Next, I am thinking instead of the above, if you specify a font operator: \mathcal { ... } that overrides \mathtt. In fact I think a stack of fonts will be maintained. Fourth, i think I will make a single character identifier an exception and typeset that using \mathit. This means \mathit and \mathtt probably should NOT be used as operators! In general formulae like \mathcal X \mathcal {x + y} \mathcal (x + y) etc affect typesetting and are ALSO Felix functions. So take care to use these functions in a way that the font change make it clear that an operation is performed, and what it is performed ON. -- john skaller skaller@... http://felix-lang.org 
 Re: [Felix-language] [felix] stumped From: john skaller - 2015-04-24 23:21:10 On 25/04/2015, at 3:44 AM, Shayne Fletcher wrote: > > On Fri, Apr 24, 2015 at 1:07 PM, john skaller wrote: > fun ravel[u1,u2,r1,r2] (f1:u1->r1,f2:u2->r2) : u1 * u2 -> r1 * r2 > > ​Neat function. But I want ravel[D1,C1,D2,C2,D3,C3,....D9,C9] (f1:D1->D2, f2:D2->C2 ... f9:D9->C9): D1 * D2 *..D9 -> C1 *C2 .. C9; I can do str[D1,D2, ... D9] (p1:D1, p2:D2,.. p9:D9):string given str:T->string which should be harder, since it involves polymorphic recursion. However the latter is just a string fold of the individual components. However I don't think Ocaml can do this using any method, and I'm not sure Haskell can either (in fact Haskell doesn't even HAVE tuples AFAIK) Felix and C++ can do it. However I can't generalise it, even if you want a bool fold of some property, i.e. fix the return type. The ravel doesn't need any typeclass, it can be done with a purely parametric function, but I can't figure it out :) In Felix and C++ you have to use template instantiation to do polymorphic recursion over a typeclass, you cannot do it without a typeclass, and I see no way to do it in Felix at all. In fact, short of making "ravel" a compiler intrinsic, I see no way to do it. If I am having to add a compiler intrinsic or two, I would want to add the most general ones. Hence reading category theory papers to see what the most general ones are. -- john skaller skaller@... http://felix-lang.org 
 [Felix-language] stumped From: john skaller - 2015-04-24 17:08:03 I am stumped at the moment defining certain operators on tuples. If you look at src/lib/std/datatype/tuple.flx you will see there is general way to apply a function T -> K T * T -> K to a tuple, where K is a constant type. For example T -> string // Str T * T -> bool // Eq are defined. See also that we can do F T0, F T1 ... F TN -> F (T0, T1 .. TN) in some cases, such as in src/lib/std/algebra/set.flx we can "almost" define \otimes (set_form[T0], set_form[T1],.. set_form[TN] ) I say almost because actually we can do var x = { x: int | x > 0} \otimes { x: double | x > 0.0} \otimes { x:string | x > "H" }; println$(24,3.2,"Hello") \in x; but this is right associative. What I REALLY want to define is: \otimes (s1,s2,s3); but this doesn't work. It would be a "generic fold". Another example: //$ parallel composition // notation: f \times g fun ravel[u1,u2,r1,r2] (f1:u1->r1,f2:u2->r2) : u1 * u2 -> r1 * r2 => fun (x1:u1,x2:u2) => f1 x1, f2 x2; This function takes a pair of functions, and makes them into a single function accepting the product of the domains as its domain and the product of its codomains as the codomain. It's easy to define this for 3 or 4 components, but I want to define it for an *arbitrary* length tuple. -- john skaller skaller@... http://felix-lang.org 
 Re: [Felix-language] [felix] Maths DSSL From: Ryan Gonzalez - 2015-04-24 15:04:39 Attachments: Message as HTML Yeah, I still have to try the KaTeX stuff I was working on. Got stumped temporarily because I couldn't find an alternative to \DeclareMathOperator. On Fri, Apr 24, 2015 at 2:56 AM, john skaller wrote: > The below will give cute display in Felix code, if displayed by flx_web. > The "font" operators are just ordinary functions .. so you have to actually > define them if you want stuff to work! > > > //////////////////////////////////////////////////////////////////////////////// > // ordinary and mathmode > var x = X; // ordinary > var x = $$X$$; // mathmode > > // these are all TeX commands so x ^ \font y > // typesets correctly: note \sin is an OP symbol > // so x ^ \sin y fails, and x ^ \Gamma y works > // since \Gamma is an ORD, but the y is not raised. > > // font operators > var x = $$\mathrm X$$; // mathrm > var x = $$\mathit X$$; // mathit > var x = $$\mathfrak X$$; // mathfrak > var x = $$\mathbb X$$; // mathbb > var x = $$\mathbf X$$; // mathbf > var x = $$\mathcal X$$; // mathcal > var x = $$\mathscr X$$; // mathscr > var x = $$\mathsf X$$; // mathscr > var x = $$\mathtt X$$; // mathtt > > // modifiers > var x = $$\acute X$$; // acute > var x = $$\check X$$; // check > > var x = $$x ^ \binom {\mathtt x} {\mathtt y}$$; > /////////////////////////////////////////////////////////////// > > However there are a couple of "gotchas". The first is that in TeX > in math mode a variable is a single character. But that's NOT how > Felix would interpret > > f ABC > > is we happen to write > > $$\mathcal ABC \} > > then the \mathcal function will apply to variable ABC, but it will > only display caligraphic symbol A. This is similar to: > > xyz > > which maths thinks is three variables but Felix thinks is one. > The typeset version is math italic, and it reads OK in this case > but really, it should be typeset in teletype font and boxed into > a single atom: > > \mathtt {xyz} > > To make this work *properly* will have to fiddle with flx_web's > flx2html plugin so that the actual characters put in the HTML > are fudged even more than at present: in particular {} > inserted like above will be invisible, so the "effect" which is applied > to something had better be visible to the reader (because now the > grouping symbols will be gone). > > At present, if MathJaX isn't available the code is "more or less" raw > as you wrote it in your editor. With improved fudging for more > betterer display (sic) this distance between what you wrote and the > HTML will be much larger. > > -- > john skaller > skaller@... > http://felix-lang.org > > > > -- > You received this message because you are subscribed to the Google Groups > "Felix Language" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to felix-language+unsubscribe@... > To post to this group, send email to felix-language@... > Visit this group at http://groups.google.com/group/felix-language. > For more options, visit https://groups.google.com/d/optout. > -- Ryan [ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong. http://kirbyfan64.github.io/   [Felix-language] Maths DSSL From: john skaller - 2015-04-24 07:57:59 The below will give cute display in Felix code, if displayed by flx_web. The "font" operators are just ordinary functions .. so you have to actually define them if you want stuff to work! //////////////////////////////////////////////////////////////////////////////// // ordinary and mathmode var x = X; // ordinary var x = \(X$$; // mathmode // these are all TeX commands so x ^ \font y // typesets correctly: note \sin is an OP symbol // so x ^ \sin y fails, and x ^ \Gamma y works // since \Gamma is an ORD, but the y is not raised. // font operators var x = $$\mathrm X$$; // mathrm var x = $$\mathit X$$; // mathit var x = $$\mathfrak X$$; // mathfrak var x = $$\mathbb X$$; // mathbb var x = $$\mathbf X$$; // mathbf var x = $$\mathcal X$$; // mathcal var x = $$\mathscr X$$; // mathscr var x = $$\mathsf X$$; // mathscr var x = $$\mathtt X$$; // mathtt // modifiers var x = $$\acute X$$; // acute var x = $$\check X$$; // check var x = $$x ^ \binom {\mathtt x} {\mathtt y}$$; /////////////////////////////////////////////////////////////// However there are a couple of "gotchas". The first is that in TeX in math mode a variable is a single character. But that's NOT how Felix would interpret f ABC is we happen to write $$\mathcal ABC \} then the \mathcal function will apply to variable ABC, but it will only display caligraphic symbol A. This is similar to: xyz which maths thinks is three variables but Felix thinks is one. The typeset version is math italic, and it reads OK in this case but really, it should be typeset in teletype font and boxed into a single atom: \mathtt {xyz} To make this work *properly* will have to fiddle with flx_web's flx2html plugin so that the actual characters put in the HTML are fudged even more than at present: in particular {} inserted like above will be invisible, so the "effect" which is applied to something had better be visible to the reader (because now the grouping symbols will be gone). At present, if MathJaX isn't available the code is "more or less" raw as you wrote it in your editor. With improved fudging for more betterer display (sic) this distance between what you wrote and the HTML will be much larger. -- john skaller skaller@... http://felix-lang.org   [Felix-language] negated comparisons From: john skaller - 2015-04-03 18:19:07 Next commit, you can write: x not < y and \( x \not\less y$$ Both not and \not mean the same, however not is printed "not" as written, whereas \not IN MATH MODE ONLY will cause the following TeX operator to be negated by strikeout. We need this because whilst TeX defines \nsubseteq it does not define \nsubset. You have to write \not\subset. Note \not\subseteq will work as well, however, the special form \nsubseteq is provided to make the struck out symbol more beautiful. Do not confuse \not with \lnot. The latter is boolean negation operator, it applies to expressions, and it has looks like logic not symbol, this has a different precedence than "not" applied to an expression. Do not write \not expr, it will neither work, nor typeset correctly. use \not to cancel comparison operators. -- john skaller skaller@... http://felix-lang.org 
 [Felix-language] Sets From: john skaller - 2015-03-31 13:34:55 here is some sample code using sets // find all the numbers < 10 whose squares are the sum of two primes begin var primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 ) ; var squares = (1,4,9,16,25,36,49,64,81,100); var primepairs = {x,y : int * int | x \in primes and y \in primes}; //var sumissquare = {i,j: int^2 | i + j \in squares }; fun sum (i:int, j:int) => i + j; var sumissquare = invimg (sum, squares); var square_sum_of_primes = sumissquare \cap primepairs; for var i in 1 upto 100 do for var j in i upto 100 do if (i,j) \in square_sum_of_primes do println$(i+j).str + "="+i.str+"+"+j.str; done done done end Now, the thing to note here is that the kind of sets we have here are just fancy predicates. We can form the conjunction of two predicates like this: fun (x:int) => P x and Q x so what's the big deal with sets? Well, you don't need the "fun" binder to compose them { x:int | P x } \cap { y:int | Q y } In fact I'm going to implement this: P and Q as well :) -- john skaller skaller@... http://felix-lang.org   Re: [Felix-language] Pretty printer From: john skaller - 2015-03-30 13:50:11 On 31/03/2015, at 12:36 AM, john skaller wrote: > > flx --felix=build.fpc src/tools/flx_pretty.flx --style > > Prints the CSS required for the colourisation, in  [Felix-language] Pretty printer From: john skaller - 2015-03-30 13:38:23 For the purpose of embedding Felix code in HTML documents, I have made a new tool: src/toolsflx_pretty.flx flx --felix=build.fpc src/tools/flx_pretty.flx --style Prints the CSS required for the colourisation, in  Re: [Felix-language] [felix] fix patterns From: john skaller - 2015-03-30 11:02:11 On 30/03/2015, at 7:18 PM, Martin DeMello wrote: >> >> This won't work as you might expect because in that pattern NIL is a variable. >> Easy to miss. You have to write >> >> | A (_, #NIL) => .. >> >> to tell the parser the NIL is a type constructor. > > Would it be hard to make this an actual warning, viz > > warning: variable NIL has same name as constructor. did you mean #NIL? I don't know, it could be quite hard. It would mean at least doing a lookup on EVERY variable name used. The problem is that the "desugaring" of pattern matching is done long before it is possible to do any lookup. So by the time the compiler comes to bind the code, it has no idea it's dealing with a pattern match variable. Pattern matches are basically macros. You can, in fact, invent your own. It basically goes: if (!_match_ctor_CTOR (arg)) goto next_case; var arg1, arg2 = _ctor_arg_CTOR (arg); // do handler goto endmatch; next_case: .... See src/lib/std/datatype/ralist.flx, a purely functional random access list, with O(log N) consing and indexed lookup. Since this type is "abstract" in some sense, there is no builtin way to pattern match on it (you can pattern match on the implementation details though). But we can fix that! CHECK FOR A MATCH: fun _match_ctor_Cons[T] (x:ralist[T]) =>not ( ralist_empty x); fun _match_ctor_Empty[T] (x:ralist[T]) => ralist_empty x; IF WE GOT A MATCH, get the head and tail: fun _ctor_arg_Cons[T] (x:ralist[T]) : T * ralist[T] = and now we can write: match some_ralist with | Empty => ... | Cons (head, tail) => ... and it will work by calling the above functions in an "if then else" chain. Anyhow the point is, by the time we have to bind this code (i.,e. do lookup) it's very hard to know which variables are pattern variables. It's even hard to know if the variable "got used". -- john skaller skaller@... http://felix-lang.org   Re: [Felix-language] [felix] fix patterns From: john skaller - 2015-03-30 08:03:12 On 30/03/2015, at 1:24 PM, Ryan wrote: > find . -name \*.flx -o -name \*.fdoc -exec sed -i 's/\?([A-Za-z][A-Za-z0-9_]*)/\1/' {} \; > > Does it all in-place, though. And only allows glob matches on filenames ... enuf for this case though. BTW: WARNING. When converting code to the new format BEWARE: union X = | NIL | A of X*X; match x with | A (_, NIL) => ... .. This won't work as you might expect because in that pattern NIL is a variable. Easy to miss. You have to write | A (_, #NIL) => .. to tell the parser the NIL is a type constructor. -- john skaller skaller@... http://felix-lang.org   Re: [Felix-language] [felix] fix patterns From: Ryan - 2015-03-30 02:24:56 Attachments: Message as HTML find . -name \*.flx -o -name \*.fdoc -exec sed -i 's/\?([A-Za-z][A-Za-z0-9_]*)/\1/' {} \; Does it all in-place, though. john skaller wrote: >Using a nice tool, flx_batch_replace: > >/usr/local/lib/felix/felix-latest/host/bin/flx_batch_replace -v src >'.*\.(flx|fdoc)' 'fixup/src/${0}' '\?([A-Za-z][A-Za-z0-9_]*)' '\1' >cp -r fixup/src/* src > >Be interested how to do that with standard unix tools. > >I do note the inconsistent replacement notation ${group} for files, >but \group for strings. Internally these search and replace operations >are in fact similar. I put the${group} in because its so hard to type >\1 >inside a string and get the quoting right. OTOH in bash ${1} is the >first >command line argument so that needs to be quoted right too. > > >-- >john skaller >skaller@... >http://felix-lang.org > > > >-- >You received this message because you are subscribed to the Google >Groups "Felix Language" group. >To unsubscribe from this group and stop receiving emails from it, send >an email to felix-language+unsubscribe@... >To post to this group, send email to felix-language@... >Visit this group at http://groups.google.com/group/felix-language. >For more options, visit https://groups.google.com/d/optout. -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. Check out my website: http://kirbyfan64.github.io/  [Felix-language] fix patterns From: john skaller - 2015-03-30 02:15:29 Using a nice tool, flx_batch_replace: /usr/local/lib/felix/felix-latest/host/bin/flx_batch_replace -v src '.*\.(flx|fdoc)' 'fixup/src/${0}' '\?([A-Za-z][A-Za-z0-9_]*)' '\1' cp -r fixup/src/* src Be interested how to do that with standard unix tools. I do note the inconsistent replacement notation ${group} for files, but \group for strings. Internally these search and replace operations are in fact similar. I put the${group} in because its so hard to type \1 inside a string and get the quoting right. OTOH in bash ${1} is the first command line argument so that needs to be quoted right too. -- john skaller skaller@... http://felix-lang.org   Re: [Felix-language] review of brackets From: john skaller - 2015-03-29 18:55:00 On 30/03/2015, at 5:42 AM, john skaller wrote: > > I am looking at some more short forms, such as > > if(x)stmt; > while(x)stmt; You can of course do this now: for(i=0; i<10; ++i;) stmt; Note the ";" after the ++i. -- john skaller skaller@... http://felix-lang.org   [Felix-language] review of brackets From: john skaller - 2015-03-29 18:43:06 Apart from in structs, unions, and function/procedure definitions, here is a possibly incomplete catalogue: { expr } --> function returning expr { stmt; stmt; expr } -> function returning expr { stmt; stmt; return expr; } -> function returning expr { stmt; stmt; } --> procedure { pattern : type | expr } --> set form ( expr ) --> expr ( expr, expr ) --> tuple (x=expr, y=expr) -> record struct {x = expr; y=expr; } -> record (deprecated) ( stmt; stmt; expr ) --> expr // means #{ stmt; stmt; expr } () --> unit tuple ( var expr ) --> expr (eagerly evaluated, same as (let x = expr in x)) I am looking at some more short forms, such as if(x)stmt; while(x)stmt; like C. It's not clear these will work, since they're ambiguous. An alternative (from COBOL): if x perform stmt; while x perform stmt; Note these are already allowed: if x call expr; if x goto label; if x return; cond ?? stmt; I also kind of like: 0..99 meaning a subrange of int, inclusive, and ascending order. Hece for i in 0..99 do ... but then, that's from Pascal, my training language (actually I learned Fortran first, and then Compass Assembler ..) Yep, I used Pascal for years, then C++, when it got multiple inheritance. And I learned C after that :) [I don't count learning BCPL .. :] -- john skaller skaller@... http://felix-lang.org   Re: [Felix-language] [felix] Set form From: john skaller - 2015-03-29 01:26:17 I am going to investigate set forms now. There is a serious issue with specialisation and deduction here. Felix is "less than capable" doing this. It's a hard problem. C++ is a bit better. It can deduce the T in "vector". Felix can do that kind of thing too, given a functor constant such as vector, but it cannot do this given a type U instantiated as F[U] for some F, that would require polyadic deduction. Note, it CAN do it for array[T,N] because that's just a typedef for T^N. So now, the problem is roughly: to, say, fund the union of two lists representing a set we can just concatenate the lists. For two set forms, which are also sets, we just make a set form whose predicate is the disjunction of the argument set forms. Note, we cannot actually find these predicates, so we have to use A \cup B = { x | x \in A or x \in B } which is horribly inefficient because it makes an object linked to two other objects and has to use indirect dispatch, and so cannot optimise the predicate. Eg not (not A) is A but we can't do that optimisation with set forms. Anyhow the purpose of this post is to talk about patterns: (?x,?y) At present you can match against Some x you do not need Some ?x or Some var x. This ONLY works in some cases, where the variable is explicitly the argument of a constructor, that is, in a form like F x recursively. The choice is made very early in compilation where pattern matching is reduced to conditionals, in other words, it is entirely syntax driven, not type information is available. no lookups can be done. The solution is found in ATS. In ATS, all constructors have an argument, possibly unit. So universally in the form F x x is a variable and F a constructor. The only exception is literals: 1.0, "hello" So for example Empty is NOT allowed, it requires an argument: Empty () because in ATS there's no such thing as a "constant constructor" other than literals. Felix copies Ocaml, and allows constant constructors (even though the idea is basically nonsense). In particular in theory you would have to write true(), false() everywhere (although the parser could define true -> True () to fix that). BUT luckily in Felix there's another way: #Empty because that means Empty () in an expression anyhow. And this notation is ALREADY available in pattern matching. So now the BIG question: should I enforce the rule?? It is not necessary to change any unions or whatever at this stage., It is not necessary to write Empty () or #Empty in any expressions (YET). That's because the compiler, at the stage of binding expressions, has type information and can do lookups, so it knows Empty is a constant constructor. In fact, #Empty will not work!!! The only rule is that you must write #Empty in patterns to tell the compiler it is a constant constructor, not a variable name. The impact: EVERY SINGLE PATTERN MATCH including ones generated by the parser WILL HAVE TO BE CHECKED. Every program, every library file. It may be possible to "hack" more than true/false, for example, Empty, None could just be "hacked". Another option would be to get rid of constant constructors entirely. The edits would be easier -- just replace Empty with #Empty everywhere. IN fact we could even allow union opt = Some of int | #None to mean union opt = Some of int | None of unit But, I don't want to mess with the compiler at the moment... -- john skaller skaller@... http://felix-lang.org   Re: [Felix-language] [felix] Set form From: john skaller - 2015-03-28 13:20:52 Sometimes it's hard to believe Felix is SOO dang good! This works now: var squares = \{ (?x,?y) : int * int | y == x * x \} ; println$ (3,9) \in squares; The general form is \{ pattern : type | predicate \} A predicate is any expression evaluating to bool, which may use the variables in the pattern match. We have to specify the type of the pattern, and our patterns have ugly ? in them sometimes, but otherwise this is similar to a mathematical set. A set_form is a real object. Any object with a method has_elt: T -> bool acts like a set courtesy of these definition in std/algebra/set.flx: interface set_form[T] { has_elt: T -> bool; } fun \in[T] (elt:T, s:set_form[T]) => s.has_elt elt; If your object has other methods you can "cast" them away with a coercion to meet the specification. It's easy to define the union now: fun \cup[T] (A:set_form[T], B:set_form[T]) => \{ ?x : T | x \in A or x \in B \}; I will do some more work on this. * At present, \{ \} can must be used. It's possible the parser will work with plain {} * To display it right you need to go into math mode: $$\{ (?x,?y) : int * int | y == x * x \}$$ which will also display the  parents ;( I may be able to fix this, I'm not sure: not all program code looks right in math mode. * \mid works better than |, whether it should be allowed, or flx_web should just change the | I don't know (matches can be used in the expression so it could be confused .. ) -- john skaller skaller@... http://felix-lang.org 
 Re: [Felix-language] [felix] Design issue From: john skaller - 2015-03-25 21:41:37 On 26/03/2015, at 5:30 AM, Martin DeMello wrote: >>> I believe this is where you went wrong - a set isn't a container with >>> a membership operator, it's a container with a membership operator and >>> the property that all elements are distinct. >> >> How would you specify that property? > > You can't without dependent types, certainly. (I'm not even sure you > can *with* dependent types; I know very little about them). In actual > code you could always maintain the invariant by simply removing > duplicates on all set-modifying operations. I think you're missing the point. class Set[C,T] { virtual fun \in : T * C -> bool; } defines a Set as a data type with a member operator. Now, an array, even with duplicate values stored, can satisfy the axiom, because there's no requirement about duplication of elements in an array. Note there's also no requirement for an equality operator, and no size. This is not your usual mathematical set. I actually defined a Container as a Set with a length operator. Consider a regexp: RE2 "(a|b)*abb". That's a set, using the obvious rule that a string that matches the regexp is in the set. Consider also: class MultiSet[C,T] { virtual fun count: T * C -> int; } I hope it's clear there is a natural transform from MultiSet to Set using fun non-zero (x:int) => x != 0; Now also consider this: instance[T,N] Set[T^N,T] { fun \in (x:T, a:T^N) => x not-in a; } That's a perfectly good model of a set too. It's an infinite set, in this model: assert 1 \in (2,3); That really is the crux of the problem. An array can be used in an infinite number of ways as a set. You could even use 9 in (1,2,3) given by the fact 9 is the square of 3. It's a design fault in the whole concept of type classes. The problem is seen to be serious if you then pick one, and then you inherit Set into a more constrained class and that constraint can't be met. For example, and this is *the* example at hand, if you have Eq for equality and Set as above, and you then want a subset relation, SetOrd, you're screwed, because array equality and set equality required for SetOrd aren't compatible. One can certainly DEFINE an array equality that works for sets, by ignoring duplicates. So we're back to the original point: TYPE CLASSES DO NOT WORK We can actually fix the problem, just use union[T,N] ArrayAsSet_t = ArrayAsSet of T^N; instance[T,N] Set[ArrayAsSet_t[T,N],T] { ... } Note that: //////////////////// open class Streamable[ContainerType, ValueType] { virtual fun iterator : ContainerType -> 1 -> opt[ValueType]; // check if a streamable x is a subset of a set y. fun \subseteq[T with Set[T,ValueType]] (x:ContainerType, y:T) = { for v in x do if not (v \in y) goto bad; done return true; bad:> return false; } } ////////////////////// works fine and is in the library. There's just no way to use THAT subseteq operator to define an instance of SetOrd[C1, C2] because it requires a third type (the ValueType], whereas the set comparisons don't need that. Ocaml functors just work better because you have to supply a whole package as an argument, that is, the functor accepts the type parameters AND the instance functions. With type classes you can only define one function for each list of type arguments. So for example you can make array-as-set in 10 different ways by giving 10 different functions for the membership operator. -- john skaller skaller@... http://felix-lang.org 
 Re: [Felix-language] [felix] Design issue From: john skaller - 2015-03-25 10:47:39 On 25/03/2015, at 1:26 PM, Martin DeMello wrote: >> >> Set -- membership operator >> Container -- as set with a size operator (i.e. a finite set) >> > > I believe this is where you went wrong - a set isn't a container with > a membership operator, it's a container with a membership operator and > the property that all elements are distinct. How would you specify that property? -- john skaller skaller@... http://felix-lang.org 
1 message has been excluded from this view by a project administrator.

Showing results of 5880

1 2 3 .. 236 > >> (Page 1 of 236)