Permalink
Browse files

small resolver fix

some eq tests
  • Loading branch information...
1 parent 599d4e9 commit ca506b52c2866c3de0e25f5b194d30d6f0dcf1de @frabbit frabbit committed Aug 10, 2012
View
@@ -6,6 +6,6 @@
-cp ./../scutsData/src
-lib utest
--connect 127.0.0.1:1978
-
+#-D scutsDebug
#--times
#-D macrotimes
View
@@ -103,7 +103,7 @@ class Objects
public static function tup2Eq (eq1, eq2) return new Tup2Eq(eq1, eq2)
public static function optionEq (eqT) return new OptionEq(eqT)
public static function arrayEq (eqT) return new ArrayEq(eqT)
- public static function validationEq (eqF,eqS) return new ValidationEq(eqF,eqS)
+ public static function validationEq <F,S>(eqF,eqS):Eq<Validation<F,S>> return new ValidationEq(eqF,eqS)
// enumerations
@@ -239,26 +239,36 @@ private typedef IEq<T> = Implicit<Eq<T>>;
class ArrayEq_Obj
{
- public static inline function implicitObj <T>(_:IOEq<Array<T>>, eqT:IEq<T>) return O.arrayEq(eqT)
+ public static inline function implicitObj <T>(_:IOEq<Array<T>>, eqT:IEq<T>):Eq<Array<T>> return O.arrayEq(eqT)
}
class OptionEq_Obj
{
- public static inline function implicitObj <T>(_:IOEq<Option<T>>,eqT:IEq<T>) return O.optionEq(eqT)
+ public static inline function implicitObj <T>(_:IOEq<Option<T>>,eqT:IEq<T>):Eq<Option<T>> return O.optionEq(eqT)
}
class ValidationEq_Obj
{
- public static inline function implicitObj <F,S>(_:IOEq<Validation<F,S>>,eqF:IEq<F>, eqS:IEq<S>) return O.validationEq(eqF,eqS)
+ public static inline function implicitObj <F,S>(_:IOEq<Validation<F,S>>,eqF:IEq<F>, eqS:IEq<S>):Eq<Validation<F,S>> return O.validationEq(eqF,eqS)
}
class Tup2Eq_Obj
{
- public static inline function implicitObj <A,B>(_:IOEq<Tup2<A,B>>,eq1:IEq<A>, eq2:IEq<B>) return O.tup2Eq(eq1,eq2)
+ public static inline function implicitObj <A,B>(_:IOEq<Tup2<A,B>>,eq1:IEq<A>, eq2:IEq<B>):Eq<Tup2<A,B>> return O.tup2Eq(eq1,eq2)
}
class IntEq_Obj
{
public static inline function implicitObj <A,B>(_:IOEq<Int>) return O.intEq
}
+
+class FloatEq_Obj
+{
+ public static inline function implicitObj <A,B>(_:IOEq<Float>) return O.floatEq
+}
+
+class StringEq_Obj
+{
+ public static inline function implicitObj <A,B>(_:IOEq<String>) return O.stringEq
+}
/// SHOWS
private typedef IOShow<T> = ImplicitObject<Show<T>>;
@@ -1,4 +1,5 @@
package hots.macros;
+import hots.Of;
class ImplicitInternal
{
@@ -20,6 +21,8 @@ class ImplicitInternal
public static inline function isValidConversionFunction <A,B>(from:A, to:B->Void, res:A->B):Void return null
+ public static inline function neededIsOfType <A>(t:Of<Dynamic, Dynamic>->Void):Void return null
+
public static inline function castCallbackTo0 <A,B> (f:A->(Void->B), c:Dynamic):A->B return cast c
public static inline function castCallbackTo1 <A,B,C> (f:A->(B->C), c:Dynamic):A->B->C return cast c
@@ -545,22 +545,35 @@ class ImplicitResolver
var upcast = macro $param.implicitUpcast();
+
+
+ var neededIsMono = switch (neededToType(needed)) {
+ case TMono(_): true;
+ default: false;
+ }
+
+ //var neededIsOf = macro $helper.neededIsOfType($needed);
+ // TODO check against of and ofof to make sure that upcast is only done when neccessary
#if scutsDebug
trace("-------------- try parameter upcasting first ------------");
trace("Success: " + isNeeded(upcast, needed));
+ trace("Is Also Normal: " + isNeeded(param, needed));
+ trace("For needed: " + prettyType(neededToType(needed)));
+ trace("Param: " + prettyTypeOfExpr(param));
+ trace("IsOfType: " + isTypeable(macro $helper.neededIsOfType($needed)));
trace("-----------------------------------------");
#end
- return if (isNeeded(upcast, needed)) {
+ return if (!neededIsMono && isNeeded(upcast, needed)) {
#if scutsDebug
trace("Upcasted Type: " + prettyTypeOfExpr(upcast));
#end
upcast;
} else {
- var accept = isNeeded(param, needed);
+ var normal = isNeeded(param, needed);
#if scutsDebug
- if (accept) {
+ if (normal) {
trace("--------------Param accepted-----------------");
printTypeOfExpr(param, "Found");
@@ -575,7 +588,7 @@ class ImplicitResolver
}
#end
- if (accept) {
+ if (normal) {
param;
} else {
View
@@ -3,6 +3,7 @@ package;
+import hots.EqTest;
import hots.MonadTransformersTest;
import hots.ImplicitScopeTests;
@@ -27,6 +28,7 @@ class AllTests
runner.addCase(new UnderscoreTests());
runner.addCase(new MonadsTest());
runner.addCase(new MonadTransformersTest());
+ runner.addCase(new EqTest());
@@ -33,6 +33,13 @@ class MonadTransformersTest
A.same(Some(Success(2)), actual);
}
+ public function testFlatMapOnValidationTransformerMonad ()
+ {
+ var v = Some(Success(1));
+ var actual = v.validationT().flatMap((function (x) return Some(Success(x + 1))).validationFT());
+ A.same(Some(Success(2)), actual);
+ }
+
public function testChainedArrayTransformerMonad ()

0 comments on commit ca506b5

Please sign in to comment.