Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 19th, 2010, 09:23 PM
Fewmitz Fewmitz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2008
Posts: 47 Fewmitz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 4 m 52 sec
Reputation Power: 0
Scala case classes

Working with case classes, I'm not sure how the declaration for case class objects works

My code is below:

Code:
abstract class Tree[T]
case object Empty extends Tree
case class Binary[T](elem: T, left: Tree[T], right: Tree[T]) extends Tree[T]
...
def preOrder[T](t: Tree[T]):List[T] = t match{
		case Empty => List()
		case Binary(e, l, r) => List(e):::preOrder(l):::preOrder(r)
	}
...
val test = Binary[Int](1, Empty, Empty)


But the declaration doesn't work. I know the logic for the preOrder method is right. I get an error when declaring Test that it requires a Tree[Int] for the second and third arguments, but Empty is a descendant of Tree. Changing the declaration of Empty to type T gives me this error:

type mismatch; found object p2.Empty required2.Tree[T]

Thanks in advance.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Scala case classes

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap