[ ai, constraints, control, failure, library, monads ] [ Propose Tags ]

Nondeterministic computations

## Modules

[Index]

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

#### Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

• No Candidates
Versions [RSS] 1.0, 1.2, 1.4, 1.5 base (>=4.8 && <5), containers, mtl (>=2 && <2.3) [details] LicenseRef-LGPL Andrei Barbu Andrei Barbu Revision 1 made by HerbertValerioRiedel at 2019-06-01T09:03:45Z Control, AI, Constraints, Failure, Monads head: git clone http://github.com/abarbu/nondeterminism-haskell by AndreiBarbu at 2015-10-19T18:04:43Z LTSHaskell:1.5, NixOS:1.5, Stackage:1.5 2 direct, 0 indirect [details] 3314 total (17 in the last 30 days) 2.0 (votes: 1) [estimated by Bayesian average] λ λ λ Docs available Last success reported on 2015-10-19

[back to package description]

# Nondeterminism

This package is available via Hackage where its documentation resides.

This provides nondeterministic computations in Haskell. It implements an Amb monad in which you can perform nondeterministic choices along with a monad transformer version, AmbT.

## Amb

An example which finds Pythagorean triplets up to a certain size, project Euler problem 9.

import Control.Monad
pyTriple :: (Num t, Ord t) => t -> Amb r (t, t, t)
pyTriple n = do a <- anIntegerBetween 1 n
b <- anIntegerBetween (a + 1) n
c <- anIntegerBetween (b + 1) n
when (a*a + b*b /= c*c) empty
return (a,b,c)
length $allValues$ pyTriple 100


More examples can be found in tests/test.hs.

## Future

• allValues is not lazy in its return value