Skip to content

Instantly share code, notes, and snippets.

@jaimefjorge
Created September 15, 2011 17:57
Show Gist options
  • Save jaimefjorge/1219966 to your computer and use it in GitHub Desktop.
Save jaimefjorge/1219966 to your computer and use it in GitHub Desktop.
My Scalaz error
import scalaz._
import Scalaz._
scala> val a = (_:List[Int]).partition(_ > 5)
a: List[Int] => (List[Int], List[Int]) = <function1>
scala> val b = (_:List[Int]).partition(_ > 10)
b: List[Int] => (List[Int], List[Int]) = <function1>
scala> val c = (_:List[Int]).map(_ + 1)
c: List[Int] => List[Int] = <function1>
scala> a andThen b.first andThen c.first.first apply List(1,2,3,20,30,40,50,100,200,300)
res0: ((List[Int], List[Int]), List[Int]) = ((List(21, 31, 41, 51, 101, 201, 301),List()),List(1, 2, 3))
scala> a andThen b.first andThen c.first.second apply List(1,2,3,20,30,40,50,100,200,300)
<console>:17: error: polymorphic expression cannot be instantiated to expected type;
found : [C(in method first), C(in method second)](C(in method second), (List[Int], C(in method first))) => (C(in method second), (List[Int], C(in method first)))
required: ((List[Int], List[Int]), List[Int]) => ?
a andThen b.first andThen c.first.second apply List(1,2,3,20,30,40,50,100,200,300)
scala> a andThen b.second andThen c.second.second apply List(1,2,3,20,30,40,50,100,200,300)
res5: (List[Int], (List[Int], List[Int])) = (List(20, 30, 40, 50, 100, 200, 300),(List(),List(2, 3, 4)))
scala> a andThen b.second andThen c.second.first apply List(1,2,3,20,30,40,50,100,200,300)
<console>:17: error: polymorphic expression cannot be instantiated to expected type;
found : [C(in method second), C(in method first)]((C(in method second), List[Int]), C(in method first)) => ((C(in method second), List[Int]), C(in method first))
required: (List[Int], (List[Int], List[Int])) => ?
a andThen b.second andThen c.second.first apply List(1,2,3,20,30,40,50,100,200,300)
@missingfaktor
Copy link

In case of c.first.first composition succeeds because types match.

scala> c.first.first
res113: (((List[Int], Nothing), Nothing)) => ((List[Int], Nothing), Nothing) = <function1>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment