[plt-scheme] The problem with Scala (OT, sorry)

From: John Clements (clements at brinckerhoff.org)
Date: Thu Mar 4 17:56:04 EST 2010

On Mar 4, 2010, at 2:52 PM, John Clements wrote:

> "Even though type Nothing is empty, it is nevertheless useful as a type parameter. For instance, the Scala library de􏰀nes a value Nil of type List[Nothing]. Because lists are covariant in Scala, this makes Nil an instance of List[T], for any element type T."
> So, I now see that the "Nothing" choice actually *does* make sense, it's just that foldLeft can't infer the right list type for its argument.  Probably this is just a left-to-right problem, where a method that's parameterized over a type that occurs in two of its arguments takes the type appearing in the first one as the one to plug into the type parameter.

Just to finish this up: I just guessed (correctly) that I could supply the parameterized type explicitly at the call to foldLeft:

scala> List(3,4,5).foldLeft[List[Int]](List():List[Nothing])({(x,y)=>y::x})
res5: List[Int] = List(5, 4, 3)

... and, without the List[Nothing] type:

scala> List(3,4,5).foldLeft[List[Int]](List())({(x,y)=>y::x})              
res6: List[Int] = List(5, 4, 3)

So, this makes the whole thing more palatable to me, but still probably not to a student.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20100304/01df6adb/attachment.p7s>

Posted on the users mailing list.