Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andresilva/pfp-scala
Probabilistic Functional Programming in Scala
https://github.com/andresilva/pfp-scala
Last synced: 12 days ago
JSON representation
Probabilistic Functional Programming in Scala
- Host: GitHub
- URL: https://github.com/andresilva/pfp-scala
- Owner: andresilva
- License: mit
- Created: 2013-12-31T13:05:50.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2014-05-31T15:16:31.000Z (over 10 years ago)
- Last Synced: 2024-12-20T22:05:47.625Z (13 days ago)
- Language: Shell
- Size: 239 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
pfp-scala
=========Probabilistic Functional Programming in Scala.
Here's an example modeling the [Monty Hall problem](http://en.wikipedia.org/wiki/Monty_Hall_problem):
```scala
sealed trait Outcome
case object Win extends Outcome
case object Lose extends Outcomedef firstChoice = uniform[Outcome, Rational].apply(Win :: Lose :: Lose :: Nil)
def switch(o: Outcome) = o match {
case Win => certainly[Outcome, Rational](Lose)
case Lose => certainly[Outcome, Rational](Win)
}// Let's test both strategies
firstChoice.plot()
// Win 1/3 #################################
// Lose 2/3 ##################################################################firstChoice.flatMap(switch).plot()
// Win 2/3 ##################################################################
// Lose 1/3 #################################
```Based on *Probabilistic Functional Programming in Haskell, Martin Erwig and Steve Kollmansberger
Journal of Functional Programming, Vol. 16, No. 1, 21-34, 2006* [[1]][1]: http://web.engr.oregonstate.edu/~erwig/papers/PFP_JFP06.pdf