fork download
  1. object Main{
  2. def doSomething(l : MyList, i : Int):MyList = {
  3. l match {
  4. case Nil() => Nil()
  5. case Cons(e,tail) if e > i => Cons(e,doSomething(tail,i))
  6. case Cons(e,tail) => doSomething(tail,i)
  7. }
  8. }
  9.  
  10. def main(args: Array[String]) {
  11. doSomething(Cons(1,Cons(2,Nil())),1)
  12. }
  13. }
  14.  
  15. case class Nil extends MyList
  16.  
  17. case class Cons(cur : Int , follow : MyList) extends MyList
  18.  
  19. object MyList {
  20. def push(n : Int, l : MyList):MyList = {
  21. Cons(n,l)
  22. }
  23. def tail(l : MyList) : MyList = {
  24. l match{
  25. case Nil() => Nil()
  26. case Cons(c,f) => f
  27. }
  28. }
  29. def pop(l : MyList) : (Int,MyList) = {
  30. l match{
  31. case Nil() => throw new IllegalArgumentException("wrong parameter")
  32. case Cons(c,f) => (c,f)
  33. }
  34. }
  35. }
Success #stdin #stdout 0.07s 211584KB
stdin
Standard input is empty
stdout
Standard output is empty