-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo2.hs
42 lines (34 loc) · 1.2 KB
/
Demo2.hs
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
{-# LANGUAGE TemplateHaskell #-}
module Demo2 where
import Logical
import NamedReqs
import NameTree
import Numerals
inRange =
$(matching [| \n ->
named "inRange" . group roman $
(named "lowerBound" . boolean $ n >= 0)
#&& (named "upperBound" . withError (show n ++" > 100") $ boolean $ n <= 100)
|])
allInRange =
$(matching [| \(a,b,c) ->
named "a" (inRange `onValue` a) #&&
named "b" (inRange `onValue` b) #&&
named "c" (inRange `onValue` c)
|])
allElements r = recursively $ \rec ->
$(matching [| \[] -> anonymous $ boolean True |]) #&&
$(matching [| \(x:xs) -> (r `onValue` x) #&& (rec `onValue` xs) |])
-- This one contains infinitely many positions, of course.
allElements' r =
$(matching [| \[] -> named "emptyList" $ boolean True |]) #&&
$(matching [| \(x:xs) -> (r `onValue` x) #&& (allElements' r `onValue` xs) |])
inRange' =
$(matching [| \n ->
named "inRange" . group roman $
(named "lowerBound" $ n `ge` 0)
#&& (named "upperBound" . withError (show n ++" > 100") $ 100 `ge` n)
|])
m `ge` n =
named "boundary" (boolean (m==n)) #||
named "non-boundary" (boolean (m >n))