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 Jump to 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
[("a:",0,"b:",1,"c:",1)
,("a:",0,"b:",2,"c:",2)
,("a:",0,"b:",3,"c:",3)
,("a:",0,"b:",4,"c:",4)
,("a:",1,"b:",2,"c:",3)
,("a:",1,"b:",3,"c:",4)]
-}