Skip to content

Instantly share code, notes, and snippets.

@paulp
Last active January 2, 2016 00:59
Show Gist options
  • Save paulp/8227277 to your computer and use it in GitHub Desktop.
Save paulp/8227277 to your computer and use it in GitHub Desktop.
scala> def drop[T](xs: List[T], n: Int) = if (xs.isEmpty || n <= 0) xs else drop(xs.tail, n - 1)
drop: [T](xs: List[T], n: Int)List[T]
scala> drop(List(1,2,3,4,5), 3)
res0: List[Int] = List(4, 5)
@milessabin
Copy link

What happens to the inferred type of h if you define it as "def h() = if (true) h() else 123"?

@paulp
Copy link
Author

paulp commented Jan 2, 2014

scala> def h() = if (true) h() else 123
h: ()Int

@paulp
Copy link
Author

paulp commented Jan 2, 2014

Or to the limit:

scala> def h() = if (true) h() else h()
h: ()Nothing

@paulp
Copy link
Author

paulp commented Jan 2, 2014

scala> def rand = scala.util.Random.nextBoolean
rand: Boolean

scala> def f[A <: String, B <: String](x: A, y: B) = (
     |   if (rand) f(x, y)
     |   else if (rand) f(y, y)
     |   else x -> y
     | )
f: [A <: String, B <: String](x: A, y: B)(String, B)

@non
Copy link

non commented Jan 3, 2014

So... who do I have to kill to get this into scala/master ?

@paulp
Copy link
Author

paulp commented Jan 3, 2014

I'm no longer in the scalac game. If someone wants to try to dredge it from my inevitable fork they will be welcome.

@kiritsuku
Copy link

For this to happen you should upload your branches to github.

@paulp
Copy link
Author

paulp commented Jan 3, 2014

I'm aware of the prerequisite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment