On 22/06/2012, at 12:14 AM, john skaller wrote:

> 
> Interestingly there's no problem with ^, the problem is with *.
> Felix can handle ^ because it's a left associative binary operator
> so any number of these can be handled by recursion (Felix type
> functions can be recursive). But operator * is not binary but
> n-ary.


Aha! I know how to fix this now! 

        A * B * C -> flatten ( a \* b \* c)

where \* is left associative. The important thing: Felix already
has a flatten function, but it doesn't work. The reason is flatten
above isn't a function, its a **constructor** just lie * \* etc.

If this is to work then src/lib/std/tuple.flx should reduce to a single
set of binary cases.

Roughly:

instance[T,U] Str[T*U] {
   fun str (t:T, u:U) => "("+str t + ", " + str u+")";
}

becomes recursive, matching first T, but U is "rest of the tuple".
So we have to write instead:

instance [T,U] Str[ flatten (T \* U)] { 
   fun str (t:T, u:U) => "("+str t + ", " + Str[U]::str u+")";
}

Note that here the str u is now matching the "rest of the tuple"
which has 1 less component. This calls str recursively,
but note this is NOT ordinary recursion, it's polymorphic
recursion. We also have to code a "final" case to stop
the recursion. Normally this would be unit, but that messes
things up so we will terminate with a final binary T * U
(not flattern T \*U). Hmm ....

--
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