5 | module Search.HDecidable
7 | import Data.List.Lazy
8 | import Data.List.Lazy.Quantifiers
9 | import Data.List.Quantifiers
12 | import Search.Negation
21 | record HDec (a : Type) where
24 | evidence : So isTrue -> a
29 | yes = MkHDec True . const
34 | no = MkHDec False absurd
37 | fromDec : Dec a -> HDec a
38 | fromDec (Yes p) = yes p
42 | fromMaybe : Maybe a -> HDec a
43 | fromMaybe = maybe no yes
46 | toMaybe : HDec a -> Maybe a
47 | toMaybe (MkHDec True p) = Just (p Oh)
48 | toMaybe (MkHDec False _) = Nothing
55 | interface AnHDec (0 t : Type -> Type) where
56 | toHDec : t a -> HDec a
58 | public export AnHDec Dec where toHDec = fromDec
59 | public export AnHDec HDec where toHDec = id
60 | public export AnHDec Maybe where toHDec = fromMaybe
67 | map f (MkHDec b prf) = MkHDec b (f . prf)
70 | Applicative HDec where
72 | MkHDec False prff <*> _ = MkHDec False absurd
73 | _ <*> MkHDec False _ = MkHDec False absurd
74 | MkHDec True prff <*> MkHDec True prfx
75 | = yes (prff Oh (prfx Oh))
79 | Alternative HDec where
81 | p@(MkHDec True _) <|> _ = p
86 | MkHDec True x >>= f = f (x Oh)
90 | Show f => Show (HDec f) where
91 | show (MkHDec True p) = "True: " ++ show (p Oh)
99 | (&&) : (AnHDec l, AnHDec r) => l a -> r b -> HDec (a, b)
100 | p && q = [| (toHDec p, toHDec q) |]
104 | (||) : (AnHDec l, AnHDec r) => l a -> r b -> HDec (Either a b)
105 | p || q = [| Left (toHDec p) |] <|> [| Right (toHDec q) |]
112 | not : (AnHDec l, Negates na a) => l na -> HDec (Not a)
113 | not p = [| toNegation (toHDec p) |]
116 | export infixr 3 ==>
120 | (==>) : (AnHDec l, AnHDec r, Negates na a) => l na -> r b -> HDec (a -> b)
121 | p ==> q = [| contra (not p) |] <|> [| const (toHDec q) |] where
122 | contra : Not a -> a -> b
123 | contra na a = void (na a)
130 | any : AnHDec l => (xs : List a) -> ((x : a) -> l (p x)) -> HDec (Any p xs)
132 | any (x :: xs) p = [| Here (toHDec (p x)) |] <|> [| There (any xs p) |]
136 | all : AnHDec l => (xs : List a) -> ((x : a) -> l (p x)) -> HDec (All p xs)
138 | all (x :: xs) p = [| toHDec (p x) :: all xs p |]
144 | any : AnHDec l => (xs : LazyList a) -> ((x : a) -> l (p x)) -> HDec (Any p xs)
146 | any (x :: xs) p = [| Here (toHDec (p x)) |] <|> [| There (any xs p) |]