Haskell Quiz/Constraint Processing/Solution Jethr0

From HaskellWiki
< Haskell Quiz‎ | Constraint Processing
Revision as of 10:42, 19 December 2006 by JohannesAhlmann (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Basically there's nothing to be done in haskell for this quiz.

As the List Monad already provides non-deterministic evaluation with "guard" as a description of constraints, you really just have to write the problem in the List Monad and be done with it.

Of course one could write all kinds of wrapping hackery, but I think from the standpoint of usability and conciseness the built-in behaviour of haskell is already pretty optimal.

constr = do a <- [0..4]
            b <- [0..4]
            c <- [0..4]
            guard (a < b)
            guard (a + b == c)
            return ("a:",a,"b:",b,"c:",c)

> constr