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 skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language