On Wed, 2007-04-11 at 19:58 -0700, Erick Tryzelaar wrote:
> A couple more, not necessarily having to do with the paper:
> 
> 1. warn if not exhaustively matching all patterns.
> 
> 
> 2. aggregating patterns:
> 
> match x with
> | 5 | 6 => ...
> | 7 => ...
> | _ => ...
> endmatch
> 
> and with variable binding:
> 
> match x with
> | Cons(?x, Cons(_, _)) | Cons(?x, Empty[int]) => ...
> | _ => ...
> endmatch

It needs:

| (X (?x,?y) | Y (1,?y) with x = 99) => ...

i.e. a way to synthesise variables. I proposed this for Ocaml too.
The match construction is ugly:

        match e with
        | X ?y => y+x

is really:

        let fun f x => y + x in
        match e with
        | X ?x => f x

but there's no 'let fun' construction. With this representation:

        | (X (?x,?y) | Y (1,?y) with x = 99) => ...

just becomes

        let fun f (x,y) =  .. in match . . with
        | X (?x,?y) => f (x,y)
        | Y (1,?y)  => f (99,x)

Remember let ?a = b in c is just sugar for

        match b with ?a => c

The problem here, trivially, is that there's no 'scope'
in which to put the match handler abstraction, because it's
a function. Of course you CAN do it by:

        let f = (fun x,y) =>  ..) in match . . with
        | X (?x,?y) => f (x,y)
        | Y (1,?y)  => f (99,x)

i.e. use a lambda expression.

Felix pattern match handlers automatically inline such
a notional handler: in fact what it does is something
like:

        let e = match_argument in
        if match_X e then f (x,y) replacing
                x = extractor_x e
                y = extractor_y e
        else if match_Y e then f (99,x) replacing ..

i.e. it directly replaces x,y etc in the argument
term .. BEFORE type checking .. with extractors
for the variables.

The extractor for y in 

        (_,?y)

is just the projection called 'snd' in Ocaml. The match
checker is the identity (tuple patterns always match).

The extractor for a union member | X y with 
pattern | X ?y is just

        ctor_arg (u) ::= u.data (cast to arg type)

and the match checker is 

        X = index u ::= X = u.variant

where u is just a _uctor_. 

What we REALLY need is Jay pattern matching, but that requires
actively building up the extractors at run time.



-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to