scalaz/scalaz — Issue #72: DSL notation with <*> won't compile without parens
Author: ornicar
Created: 2012-02-11 01:56:50+00:00
State: open

I couldn't come with a better issue title.

Let's create a small validation DSL

scala> val validator = new { def fail(msg: String) = failure[String, Int](msg)
validator: java.lang.Object{def fail(msg: String): scalaz.Validation[String,Int]} = $anon$1@1e818d28

This will compile and run:

scala> (validator fail "foo") <*> (validator fail "bar") map ((_: Int) => (_: Int) => 1))
res30: scalaz.Validation[String,Int] = Failure(barfoo)

But this won't compile:

scala> validator fail "foo" <*> (validator fail "bar" map ((_: Int) => (_: Int) => 1))
:15: error: type mismatch;
found : scalaz.Validation[String,Int => Int]
required: java.lang.Comparable[java.lang.String => ?]
validator fail "foo" <*> (validator fail "bar" map ((_: Int) => (_: Int) => 1))

Note that I omitted the parens **(**validator fail "foo"**)**. It seams the compiler treats the first char of the operator `<*>` as a `lessThan`.
It can be worked around by adding parens, or by aliasing the `<*>` function.