Scala import problems - error: not found: value -
i'm haskeller looking scala. i'm meeting frustration not code, imports/packages.
i have 2 files, test.scala , lists.scala.
// lists.scala package problems object lists { def last(list: list[any]): option[any] = list match { case nil => none case x :: nil => some(x) case _ :: xs => last(xs) } } and:
// test.scala import problems._ object test extends app { println("starting tests...") println(last(list(1,2,3,4,5))) } test.scala not compile. running scalac test.scala lists.scala yields:
test.scala:5: error: not found: value last println(last(list(1,2,3,4,5)) yet rewriting last lists.last makes succeed. doesn't defeat point of import problems._ wildcard? notice math functions can written without preceeding math. doing import math._. why won't work files well?
real aim: want able make package, test functions println in file. what's best way that? can not away object {...} in test.scala , run scala, forgoing compilation process?
doesn't defeat point of import problems._ wildcard?
no, not. using wildcard you're bringing classes/objects in package scope, not contents.
i notice math functions can written without preceding
math.doingimport math._why won't work files well?
it work, need proper import: import problems.lists._. otherwise can place functions package object.
Comments
Post a Comment