Created
May 28, 2014 15:11
-
-
Save kwstannard/2a3544952e826cc9c950 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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