File: colormap02.curry

package info (click to toggle)
curry-tools 1.0.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,492 kB
  • ctags: 121
  • sloc: makefile: 470; sh: 421
file content (42 lines) | stat: -rw-r--r-- 979 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-- constraint solving (simple generate and test) in Curry:
-- graph coloring

-- negation of =:=
diff :: a -> a -> Success
diff x y = (x == y) =:= False

{-
 This is our actual map:

 ------------------
 |       |        |
 |       |   L2   |
 |       |        |
 |  L1   |--------|
 |       |        |
 |       |   L3   |
 |       |        |
 ------------------
-}

data Color = Red | Green | Yellow

isColor :: Color -> Success
isColor Red    = success
isColor Green  = success
isColor Yellow = success

-- possible colorings:
coloring :: Color -> Color -> Color -> Success
coloring l1 l2 l3 = isColor l1 & isColor l2 & isColor l3

-- correct coloring:
correct :: Color -> Color -> Color -> Success
correct l1 l2 l3 = diff l1 l2 & diff l1 l3 & diff l2 l3

-- test+generate solution:
goal :: Color -> Color -> Color -> Success
goal l1 l2 l3 = PEVAL (correct l1 l2 l3 & coloring l1 l2 l3)

main :: (Color, Color, Color)
main = goal l1 l2 l3 &> (l1, l2, l3) where l1, l2, l3 free