On 21/05/2009, at 12:26 AM, john skaller wrote:

> There is a problem in Felix with constraint propagation .. well the
> problem is that constraints are NOT propagated.

I have no implemented some basic constraint propagation.
It is intended to be enough to handle typesets of primitive
types, that is sets of ints, floats, etc.

This now works:

///////////////////
fun g[v in int || long ] (a:v) : string = {
   fun f[u in int || long || double] (x:u)=> "int";
   return f a;
}
println$ g 1;
///////////////

Basically, f requires its argument to be an int, long, or double.
So since the argument to f  is a, and a is the argument to g,
which is required to be an int or a long, in either case it
is and int, long or double so the constraint is satisfied.

This code didn't work before. What happens is: if the constraint
on a call is not immediately satisfied, then the constraints of
the environment are checked to see if they imply the called
function's constraints.

The check basically splits a constraint up into a list
of conjuncts, and then checks if for each conjunct
of the function, at least one conjunct of the environment
implies it.

Implication only checks one kind of conjunct at the moment,
namely type matches. The branches of a type match are
compare for equality, and if that fails, the left hand branch
is skipped to the next one. The result is true unless the
LHS branch list is exhausted before the RHS list.
Except there is one special case: if the pattern
of a type match is a type variable and the variable
set of the pattern is not empty it is guessed to be
that type variable used as a wildcard: in this case
a LHS and RHS wildcard matches.

The comparison for the example is operating on

typematch v with
| int -> 1
| long -> 1
| w1 -> 0
endmatch

and

typematch u with
| int -> 1
| long -> 1
| double -> 1
| w2 -> 0
endmatch

Unification replaces u with v. The two wildcards w1, w2
are considered equal.

The routine DOES not handle general constraints. It also DOES NOT
handle out of order typematches. I may have to fix that. Basically
for the requirements we're only interested in constant patterns
yielding true (type 1) except the last case which is a wildcard
yielding false (type 0) because these are what a "y in typeset"
expression generates as the reduced form.

In otherwords we're implementing a set membership test,
only we have to do it with the code used to calculate membership,
rather than the actual typesets.

Hmm .. I stuffed something:
   test/regress/rt/rt-1.01.44-0.flx
   test/regress/rt/rt-1.01.26-0.flx
now both compile and run without printing any output and without
any error .. hmm ;(


--
john skaller
skal...@users.sourceforge.net





------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to