The Artima Developer Community
Sponsored Link

Programming in Scala Forum
Why Func literals require type casting when overloading is used

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
manas marthi

Posts: 1
Nickname: mmaun
Registered: Nov, 2016

Why Func literals require type casting when overloading is used Posted: Nov 17, 2016 3:29 AM
Reply to this message Reply
Advertisement
Ref: setction 9.4 about defining new control sctructures

I changed the "twice" example and overloaded the method.
When calling it, compiler throws error and I had to type cast the function literal. Can someone please throw some light on why it is happenning sow


def twice ( op: Int=> Int, x: Int) = {
println("twice with Int")
op (op(x))

}
def twice ( op: Double=> Double, x: Double) = {
println("twice with Double")
op (op(x))

}


twice ( (_+2) :Int=>Int, 4)
twice ( (_+2) :Double=>Double, 4)

Topic: Partially applied functions Previous Topic   Next Topic Topic: I'm confused by what s.length.toString.length means

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use