Scala 範例程式集

簡易範例

  1. abstractTypes — An example of how abstract types are used in a program
  2. bigint — User-defined integers, BigInts, are used seamlessly
  3. complexOps — Operators can be defined on user-defined classes, here complex numbers
  4. forYields — An example of the for and yield constructs
  5. extendBuiltins — Adding "!" as a new method on integers
  6. implicits — Define a new method 'sort' on arrays without changing their definition
  7. maps — Maps are easy to use in Scala
  8. match — Using pattern matching to recognize command line arguments
  9. primes — A simple, although inefficient, way to calculate prime numbers
  10. sum — Calculates the sum of the arguments supplied on the command line
  11. varargs — Java varargs can be easily used in Scala as well

進階範例

  1. addressbook — Address book to XHTML code (see also XML Processing)
  2. callccInterpreter — Interpreter with continuations using monads
  3. fors — for comprehensions (see also Sequence Comprehensions)
  4. gadts — Generalised algebraic data types
  5. lazyEvaluation — Lazy evaluation
  6. message — Actors (see also Actors for Scala)
  7. patterns — Pattern matching using case classes (see also Case Classes)
  8. extractorPatterns — Pattern matching using extractors - a flexible way of matching objects with patterns
  9. pingpong — Actors (see also Actors for Scala)
  10. properties — Properties
  11. random — Client/server application using Java sockets
  12. simpleInterpreter — Simple interpreter using monads
  13. sort — Recursive quicksort algorithm (imperative solution, see also Nested Functions)
  14. sort1 — Recursive quicksort algorithm (functional solution)
  15. timeofday — Properties (see example 1 in § 4.2 of the Scala Language Specification)
  16. vectors — Vector operations using views (see also Views)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License