2017-01-29 21:15 GMT+01:00 Michael Lindon <michael.s.lin...@gmail.com>:

> Not quite what I'm looking for. There is an assigment in the Functional
> Programming in Scala coursera course called "funsets" - purely functional
> sets. A set is defined by its characteristic functions (a predicate) and
> source code can be found here
>

Looking at it from a functional perspective, it still might be though.
Consider: You can treat any set as a predicate, but to treat a predicate as
a set, you need to add enumeration (as Christian hinted).

https://mwclearning.com/sourcecode/scala/funsets/src/
> main/scala/funsets/FunSets.scala
>

The enumeration scheme in this scala object is very simplistic: It works
for integers between -1000 and 1000. Besides being incomplete, this can
easily lead to unnecessarily exponential runtimes:

> /**
>  * The bounds for `forall` and `exists` are +/- 1000.
>  */
> val bound = 1000

> /**
>  * Returns whether all bounded integers within `s` satisfy `p`.
>  */
> def forall(s: Set, p: Int => Boolean): Boolean = {
>   val filteredSet = filter(s, p)
>   def iter(a: Int): Boolean = {
>     if (contains(s, a) && !contains(filteredSet, a)) false
>     else if (a > bound) true
>     else iter(a + 1)
>   }
>   iter(-bound)
> }

> /**
>  * Returns whether there exists a bounded integer within `s`
>  * that satisfies `p`.
>  */
> def exists(s: Set, p: Int => Boolean): Boolean = forall(s, union(s,p))

Constraint programming offers a much more sophisticated approach
towards enumeration, eagerly skipping whole subsets based on excluded
ranges. Maybe that's what the coursera is aiming for ...

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to