OK, I think this is the way forward here. A new bound combinator is introduced
for tuples:

        BTYP_tuple_cons of t * t

This combinator is only intended to be used in pattern matching.
It has the following invariant: the second t above must be a BTYP_tuple_cons
or a BTYP_tuple [] (i.e. a unit). 

Introducing the *right associative* binary operator  ** for this (ugly but will
do for now) we have:

        a * b * c = a ** b ** c ** 1 = a ** (b ** ( c ** 1))

With this, we can say:

typedef fun tuple_map (f:T->T) (x:T) =>
        typematch T with
        | ?last ** 1 => f last
        | ?head ** ?tail => f last ** tuple_map f tail
        endmatch
;

which allows us to recursively map a tuple (for example). We'd need a similar
construction for sums. 

To make this work, we basically need to allow unification:


        BTYP_tuple_cons (t1, t2) = BTYP_tuple (t1' :: t2')

by setting equation

        t1 = t1'

AND: 

        if t2' = [] then t2 = BTYP_tuple []

        else

        t2 = BTYP_tuple t2'

which will lead to recursively reconsidering an equation of the first form,
but with one less term (the head stripped off).

The point of this form is that the tail of a tuple can be represented by a 
single
type variable.

When this form is used outside pattern matching it would act as a tuple type
constructor. A similar form like ,, could be used for value matching and
construction.

We have to be careful though. We could actually use this form universally
and get rid of BTYP_tuple entirely. However because of the invariant it
is not a true type combinator (but then .. neither is array).

It's not clear exactly how to "get rid of" all uses of this term except in
pattern matches.

--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to