On 30/06/2013, at 8:50 PM, srean wrote:

> 
>         var a, b = f x;
>         d = g b;

[]

> So I want to write something lie:
> 
>         var a, d = g * = f x;
> 
> where the * is where the second component of f x would "land".

> Wont it be clearer to write
> 
> var a,d = h (f x)
> 
> where h is a helper function that passes the first as it is and calls g on 
> the second.

This would certainly work, but it isn't simpler: if you don't happen to have
such a function at hand, you have to make one.

If we can make one combinatorially it would help. Now actually we CAN do that:

        var a,d = ravel (ident, g) ( f x )

where ravel is parallel composition and ident is the identity function
(see lib/std/categ.flx).

However this is not so easy in Felix because the type of "ident" would have
to be given explicitly, since there's no overload to provide the type.

So what we want to do is "turn the g function inside out and move it over
to the LHS instead".  This is precisely what pattern matching already does
for a *fixed* set of functions. In particular for tuples, pattern matching
turns projections inside out. Looki at this example:

        match argument with
        | (?x, (?y,_), 42) => ...

See the "42" actually means

        argument . 2 == 42

and the y actually means

        y = argument . 1 . 0 

where 0, 1, 2 are first, second, and third projections. We managed to
capture 3 assignments and one comparison in a single pattern.

So what we have is any set of "arbitrary" functions:

        T --> ???

where T is the type of argument. The compiler hard codes knowledge of only
certain functions: projections, integer and string comparisons, for example.

To really understand what's happening you only need to look at the
"turn it inside out" algorithm, which is in fact completely trivial.
See "src/compiler/flx_desugar/flx_mbind.ml".

I think the function I need is the adjoint ( a sort of categorical inverse).


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




------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to