File: Guards.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 (43 lines) | stat: -rw-r--r-- 1,011 bytes parent folder | download
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
43
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=defaultrules #-}
{-# OPTIONS_CYMAKE -Wnone #-}

import Test.EasyCheck

-- Examples for multiple rules with guards:

-- Non-deterministic guard: the non-determinism is encapsulated
zero x | x<0 ? x>0 = "Not zero"
zero'default x = "Zero"

main1 = map zero [-1, 0, 1]

testZero1 = zero (-1) -=- "Not zero"
testZero2 = zero  0   -=- "Zero"
testZero3 = zero  1   -=- "Not zero"


f True _    z | z <= 1 = 1
f _    True z | z > -1 = 2
f'default _ _ _ = 3

main2 = [f True  True  (-1)
        ,f True  False (-1)
        ,f True  True  0
        ,f True  False 0
        ,f True  True  2
        ,f False True  0
        ,f False True  2
        ]

testf1 = f True  True  (-1) -=- 1
testf2 = f True  False (-1) -=- 1
testf3 = f True  True  0    <~> (1 ? 2)
testf4 = f True  False 0    -=- 1
testf5 = f True  True  2    -=- 2
testf6 = f False True  0    -=- 2
testf7 = f False True  2    -=- 2
testf8 = f False False 0    -=- 3

g x | x==0 = 0
    | x==1 = 1
g'default x = 2