The nondeterminism package

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

Nondeterministic computations


[Skip to Readme]

Properties

Versions 1.0, 1.2, 1.4
Dependencies base (>=3 && <5), containers, mtl (>=2) [details]
License LGPL
Author Andrei Barbu <andrei@0xab.com>
Maintainer Andrei Barbu <andrei@0xab.com>
Category Control, AI, Constraints, Failure, Monads
Source repository head: git clone http://github.com/abarbu/nondeterminism-haskell
Uploaded Mon Oct 19 18:20:24 UTC 2015 by AndreiBarbu
Distributions LTSHaskell:1.4, NixOS:1.4, Stackage:1.4, Tumbleweed:1.4
Downloads 665 total (8 in the last 30 days)
Rating 2.0 (1 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-10-19 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for nondeterminism-1.4

[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
import Control.Monad.Amb
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