- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Evidence parameters
Wed, 2009-09-30, 20:31
I stumbled across the following quite by chance while try to track
down an AST node position bug. It looks like an interesting new
feature ... has it been discussed anywhere?
miles@lewis:scala$ dists/latest/bin/scala
Welcome to Scala version 2.8.0.r18324-b20090930195017 (Java
HotSpot(TM) Server VM, Java 1.6.0_14).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class A[T]
defined class A
scala> class B[T : A]
defined class B
scala> implicit val as = new A[String]
as: A[String] = A@2250d5
scala> new B
res0: B[String] = B@15a4a77
Cheers,
Miles
Wed, 2009-09-30, 22:47
#2
Re: Re: Evidence parameters
On Wed, Sep 30, 2009 at 2:34 PM, Miles Sabin wrote:
> On Wed, Sep 30, 2009 at 8:31 PM, Miles Sabin wrote:
>> scala> class A[T]
>> defined class A
>>
>> scala> class B[T : A]
>> defined class B
>>
>> scala> implicit val as = new A[String]
>> as: A[String] = A@2250d5
>>
>> scala> new B
>> res0: B[String] = B@15a4a77
>
> Am I right that
>
> class A[T : B]
>
> is sugar for,
>
> class A[T](implicit evidence : B[T])
I believe so. That's how I've used it.
You can then recover B[T] with:
implicitly[B[T]]
Thu, 2009-10-01, 15:07
#3
Re: Evidence parameters
It's mentioned on the array SID. It's called a Context Bound.
On Wed, Sep 30, 2009 at 4:31 PM, Miles Sabin <miles@milessabin.com> wrote:
--
Daniel C. Sobral
Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
On Wed, Sep 30, 2009 at 4:31 PM, Miles Sabin <miles@milessabin.com> wrote:
I stumbled across the following quite by chance while try to track
down an AST node position bug. It looks like an interesting new
feature ... has it been discussed anywhere?
miles@lewis:scala$ dists/latest/bin/scala
Welcome to Scala version 2.8.0.r18324-b20090930195017 (Java
HotSpot(TM) Server VM, Java 1.6.0_14).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class A[T]
defined class A
scala> class B[T : A]
defined class B
scala> implicit val as = new A[String]
as: A[String] = A@2250d5
scala> new B
res0: B[String] = B@15a4a77
Cheers,
Miles
--
Miles Sabin
tel: +44 (0)7813 944 528
skype: milessabin
http://www.chuusai.com/
http://twitter.com/milessabin
--
Daniel C. Sobral
Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.
Thu, 2009-10-01, 15:17
#4
Re: Evidence parameters
On Thu, Oct 1, 2009 at 2:55 PM, Daniel Sobral wrote:
> It's mentioned on the array SID. It's called a Context Bound.
Yup, I saw that ... thanks.
Cheers,
Miles
On Wed, Sep 30, 2009 at 8:31 PM, Miles Sabin wrote:
> scala> class A[T]
> defined class A
>
> scala> class B[T : A]
> defined class B
>
> scala> implicit val as = new A[String]
> as: A[String] = A@2250d5
>
> scala> new B
> res0: B[String] = B@15a4a77
Am I right that
class A[T : B]
is sugar for,
class A[T](implicit evidence : B[T])
?
Cheers,
Miles