381806 (2) [Avatar] Offline
It's really unclear how we're supposed to run the code for Chapter 3. Should I be putting it in the REPL? If so, I am having heaps of trouble trying to load the List.scala file:

for example:

<console>:1: error: illegal start of definition
package fpinscala.datastructures

then if I do:

scala> :paste -raw datastructures/List.scala

when I try to use the List code with the sum function, I get teh following:

<console>:16: error: not found: value sum
case Cons(h, t) => h + sum(t)

It would be nice if it was clearer how we should be executing the code...
Ray Melton (7) [Avatar] Offline
You can use ":paste -raw" to get the package in there, but then List may no longer be in scope. Try

case Cons(h, t) => h + List.sum(t)