nondeterminism

A monad and monad transformer for nondeterministic computations.

LTS Haskell 13.28:1.4
Stackage Nightly 2019-07-18:1.4
Latest on Hackage:1.4

See all snapshots nondeterminism appears in

LicenseRef-LGPL licensed and maintained by Andrei Barbu

Module documentation for 1.4

This version can be pinned in stack with:nondeterminism-1.4@sha256:56598728aff2900c8b1d0002c1bd35420bc25289db094b73fdbfd33ddce8f8a9,1032
  • Control
    • Control.Monad
      • Control.Monad.Amb

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
Depends on 3 packages(full list with versions):
Used by 1 package in nightly-2019-06-12(full list with versions):
comments powered byDisqus