Re: scala.reflect.Manifest status
Daniel Mahler <dmahler <at> gmail.com>
2009-12-01 15:46:25 GMT
Hi Paul,
Thanks. Do you think your code is likely to make it into 2.8.0 final?
If not , does anybody know when a fully implemented Manifest is expected?
Alternatively is there a way to do something like my typeCheck example
without manifests?
thanks
Daniel
On Sat, Nov 28, 2009 at 7:25 AM, Paul Phillips <paulp <at> improving.org> wrote:
>
> On Sat, Nov 28, 2009 at 01:53:32AM +0100, Daniel Mahler wrote:
>> Is there another way to do the following:
>>
>> def manifestOf[T](implicit m : Manifest[T]) = m
>>
>> def typeCheck[T](implicit m : Manifest[T]) = (
>> if (m <:< manifestOf[AnyVal]) "Value"
>> else if (m <:< manifestOf[AnyRef]) "Reference"
>> else "???")
>>
>> scala> typeCheck[Int]
>> res8: java.lang.String = ???
>
> It looks like most of the manifest stuff is just unimplemented. I took
> a swing at it just now but I could be way off of how things are supposed
> to be done so I won't check anything in. With this patch in place it's
> pretty close to working how I'd expect it to, with two missing pieces I
> can think of at this second: a) invariant collections give the wrong
> answer and b) manifestOf[Object] is not selecting Manifest.Object, which
> is busting an assumption of mine.
>
> Here's the test case I have mostly passing. (I'm not sure these are all
> the right answers, but these are the answers...)
>
> def f1 = List(
> manifestOf[java.lang.Integer] <:< manifestOf[Any],
> manifestOf[java.lang.Integer] <:< manifestOf[AnyRef],
> manifestOf[java.lang.Integer] <:< manifestOf[AnyVal]
> )
>
> def f2 = List(
> manifestOf[Int] <:< manifestOf[Any],
> manifestOf[Int] <:< manifestOf[AnyVal],
> !(manifestOf[Int] <:< manifestOf[AnyRef])
> )
>
> def f3 = List(
> manifestOf[List[String]] <:< manifestOf[List[Any]],
> manifestOf[List[String]] <:< manifestOf[AnyRef],
> !(manifestOf[List[Any]] <:< manifestOf[List[String]])
> )
>
> // doesn't work yet, variance
> // def f4 = List(
> // !(manifestOf[Set[Any]] <:< manifestOf[Set[String]]),
> // !(manifestOf[List[String]] <:< manifestOf[List[Any]])
> // ) foreach (x => assert(x))
>
> def f5 = List(
> manifestOf[Nothing] <:< manifestOf[Any],
> manifestOf[Nothing] <:< manifestOf[AnyVal],
> manifestOf[Nothing] <:< manifestOf[AnyRef],
> manifestOf[Nothing] <:< manifestOf[String],
> manifestOf[Nothing] <:< manifestOf[List[String]],
> manifestOf[Nothing] <:< manifestOf[Null]
> )
>
> def f6 = List(
> manifestOf[Null] <:< manifestOf[Any],
> !(manifestOf[Null] <:< manifestOf[AnyVal]),
> manifestOf[Null] <:< manifestOf[AnyRef],
> manifestOf[Null] <:< manifestOf[String],
> manifestOf[Null] <:< manifestOf[List[String]],
> manifestOf[Null] <:< manifestOf[Null],
> !(manifestOf[Null] <:< manifestOf[Nothing])
> )
>
> def main(args: Array[String]): Unit = {
> List(f1, f2, f3, f5, f6).flatten foreach (x => assert(x))
> }
>
> --
> Paul Phillips | A national political campaign is better than the
> In Theory | best circus ever heard of, with a mass baptism and
> Empiricist | a couple of hangings thrown in.
> pp: i haul pills | -- H. L. Mencken
>