forked from jkff/minxmod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChecker.hs
42 lines (30 loc) · 1.17 KB
/
Checker.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 ScopedTypeVariables #-}
module Checker where
import Test.QuickCheck
import Types
import ArgTree
import Examples
--import Illustrations
import Predicates
import Data.Boolean
data Bimorphism a b = Bimorphism {
to :: a -> b,
from :: b -> a
}
flipBimorphism (Bimorphism to from) = (Bimorphism from to)
checkInjection :: Eq a => Bimorphism a b -> a -> Bool
checkInjection i x =
x == from i (to i x)
viewInjection :: Bimorphism a b -> a -> (a, b, a)
viewInjection i x =
(x, to i x, from i $ to i x)
checkIntBin (NonNegative n) = checkInjection (Bimorphism (intToHisBin::Int->[Bool]) binToInt) n
checkIntegerBin (NonNegative n) = checkInjection (Bimorphism (intToHisBin::Integer->[Bool]) binToInt) n
checkXorList = checkInjection (Bimorphism (xorList False) (deXorList False))
checkGrayCode (NonNegative n) = checkInjection (Bimorphism (grayCode::Int->[Bool]) fromGrayCode) n
checkIntegerGrayCode (NonNegative n) = checkInjection (Bimorphism (grayCode::Integer->[Bool]) fromGrayCode) n
checkPredReduce o pred x =
(ans1, ans2, ans1==ans2)
where
ans1 = toFunc pred x
ans2 = (toFunc $ reducePred o pred) x