Skip to content

Instantly share code, notes, and snippets.

@kwstannard
Created May 28, 2014 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwstannard/2a3544952e826cc9c950 to your computer and use it in GitHub Desktop.
Save kwstannard/2a3544952e826cc9c950 to your computer and use it in GitHub Desktop.
package funsets
import common._
/**
* 2. Purely Functional Sets.
*/
object FunSets {
/**
* We represent a set by its characteristic function, i.e.
* its `contains` predicate.
*/
type Set = Int => Boolean
/**
* Indicates whether a set contains a given element.
*/
def contains(s: Set, elem: Int): Boolean = s(elem)
/**
* Returns the set of the one given element.
*/
def singletonSet(elem: Int): Set = Set(elem)
/**
* Returns the union of the two given sets,
* the sets of all elements that are in either `s` or `t`.
*/
def union(s: Set, t: Set): Set = s | t
...
}
[info] Compiling 1 Scala source to /Volumes/Shared/personal_projects/functional_course/funsets/target/scala-2.10/classes...
[error] /Volumes/Shared/personal_projects/functional_course/funsets/src/main/scala/funsets/FunSets.scala:29: value | is not a member of Int => Boolean
[error] def union(s: Set, t: Set): Set = s | t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment