What would be the right place for it? Predef?
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
On 7 Feb 2013 18:09, "Pavel Zalunin" <wr4...@gmail.com> wrote:
>
> Why not:
>
> typeOps.companionOf[Beeps].apply(10) ?
Under what circumstances would you expect that to compile and yet,
Beeps(10)
wouldn't?
Cheers,
Miles
--
>
> Why not:
>
> typeOps.companionOf[Beeps].apply(10) ?
Under what circumstances would you expect that to compile and yet,
Beeps(10)
wouldn't?
I also don't see the benefit. Beneficial would be a typeclass Companion[T] provided with a macro, but a companion method over a known type?
I didn't write a macro yet, so what comes maybe wrong or blatantly obvious.
Suppose we have a macro def companion[T] = macro which returns the companion of T, such that when there is class A; object A; then companion[A] = A (where = means "same instance, same type"). Then such macro has sense only when used within another macro def or macro type with a type parameter, for which we want a companion. Such macro can't work when used within a plain def foo[T] = something method, because of erasure.
Because if we take a step back, passing around an implicit parameter at runtime as evidence of something which was completely known at compile time is a little ridiculous. Is this one possible?
--
I've written a post on Type Classes from a C# perspective here http://curiousskeptic.com/type-classes-for-c-programmers/
One thing I concluded was that Type Classes probably could be implemented relatively easy as a T4 template, combining extension methods and code generation. The result could even be distributed as a NuGet package.
BR
John