The Artima Developer Community
Sponsored Link

Programming in Scala Forum
Error in Chapter 6: p124

1 reply on 1 page. Most recent reply: Dec 30, 2007 9:52 PM by Frederic Jean

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 1 reply on 1 page
Carsten Eckelmann

Posts: 6
Nickname: careck
Registered: Jun, 2003

Error in Chapter 6: p124 Posted: Dec 27, 2007 2:53 PM
Reply to this message Reply
Advertisement
when extending class Rationale to methods that take Int as parameters the book has this:

def + (that: Int) = this * new Rationale(that)
def - (that: Int) = this * new Rationale(that)
def * (that: Int) = this * new Rationale(that)
def / (that: Int) = this * new Rationale(that)

where of course it should be:

def + (that: Int) = this + new Rationale(that)
def - (that: Int) = this - new Rationale(that)
def * (that: Int) = this * new Rationale(that)
def / (that: Int) = this / new Rationale(that)

so even concise Scala programs aren't safe from the good old copy&paste errors ;)

Cheers,
Carsten.


Frederic Jean

Posts: 4
Nickname: freddyjean
Registered: Dec, 2007

Re: Error in Chapter 6: p124 Posted: Dec 30, 2007 9:52 PM
Reply to this message Reply
I actually had to specify the return type with scala 2.6.1:

def + (that: Int): Rational = this + new Rational(that)
def - (that: Int): Rational = this - new Rational(that)
def * (that: Int): Rational = this * new Rational(that)
def / (that: Int): Rational = this * new Rational(that)


Fred

Flat View: This topic has 1 reply on 1 page
Topic: Chapt. 9: Inconsistent type declarations Previous Topic   Next Topic Topic: Chapter 3: p58

Sponsored Links



Google
  Web Artima.com   

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