on master help sign in
Merge pull request #789 from tpsinnem/master

A more precise Rel & Decidable and some reshuffling of related code

commit858b6ed6ca87f81b8139b7f602b1089c3212b066 authorEdwin Brady <edwin.brady@gmail.com> dateWed 22 Jan 2014, 02:16 (13 years ago) parent59edc7540c7c45
5 files changed+34−12
libs/base/Data/Fun.idr+8 libs/base/Data/Rel.idr+13 libs/base/Decidable/Decidable.idr+9−5 libs/base/Decidable/Order.idr+2−6 libs/base/base.ipkg+2−1
libs/base/Data/Fun.idrnew file+8
@@ -0,0 +1,8 @@
1+module Data.Fun
2+
3+--------------------------------------------------------------------------------
4+-- Build an n-ary function type from a Vect of Types and a result type
5+--------------------------------------------------------------------------------
6+Fun : Vect n Type -> Type -> Type
7+Fun [] r = r
8+Fun (t::ts) r = t -> Fun ts r
libs/base/Data/Rel.idrnew file+13
@@ -0,0 +1,13 @@
1+module Data.Rel
2+
3+import Data.Fun
4+
5+--------------------------------------------------------------------------------
6+-- Build an n-ary relation type from a Vect of Types
7+--------------------------------------------------------------------------------
8+Rel : Vect n Type -> Type
9+Rel ts = Fun ts Type
10+
11+liftRel : (ts : Vect n Type) -> (p : Rel ts) -> (Type -> Type) -> Type
12+liftRel [] p f = f p
13+liftRel (t :: ts) p f = (x : t) -> liftRel ts (p x) f
libs/base/Decidable/Decidable.idr+9−5
@@ -1,17 +1,21 @@
11module Decidable.Decidable
22
3+import Data.Rel
4+
35%access public
46
57--------------------------------------------------------------------------------
68-- Typeclass for decidable n-ary Relations
79--------------------------------------------------------------------------------
810
9−using (t : Type)
10− class Rel (p : t) where
11− total liftRel : (Type -> Type) -> Type
11+-- Note: Instance resolution for Decidable is likely to not work in the REPL
12+-- at the moment.
13+class Decidable (ts : Vect k Type) (p : Rel ts) where
14+ total decide : liftRel ts p Dec
1215
13− class (Rel p) => Decidable (p : t) where
14− total decide : liftRel {p} Dec
16+-- 'No such variable {k506}'
17+--decision : Decidable ts p => (ts : Vect k Type) -> (p : Rel ts) -> liftRel ts p Dec
18+--decision ts p = decide {ts} {p}
1519
1620using (P : Type, p : P)
1721 data Given : Dec P -> Type where
libs/base/Decidable/Order.idr+2−6
@@ -71,12 +71,8 @@ decideNatLTE x (S y) with (decEq x (S y))
7171 | Yes nLTEm = Yes (nLTESm nLTEm)
7272 | No nGTm = No (nGTSm nGTm)
7373
74−instance Rel NatLTE where
75− liftRel P = (n : Nat) -> (m : Nat) -> P (NatLTE n m)
76−
77−instance Decidable NatLTE where
74+instance Decidable [Nat,Nat] NatLTE where
7875 decide = decideNatLTE
7976
8077lte : (m : Nat) -> (n : Nat) -> Dec (NatLTE m n)
81−lte m n = decide {p = NatLTE} m n
82−
78+lte m n = decide {ts = [Nat,Nat]} {p = NatLTE} m n
libs/base/base.ipkg+2−1
@@ -23,7 +23,8 @@ modules = System,
2323 Data.ZZ, Data.Sign,
2424 Data.SortedMap, Data.SortedSet, Data.BoundedList,
2525 Data.Vect, Data.HVect, Data.Vect.Quantifiers,
26− Data.Floats, Data.Complex, Data.Heap,
26+ Data.Floats, Data.Complex, Data.Heap, Data.Fun,
27+ Data.Rel,
2728
2829 Control.Isomorphism,
2930 Control.Monad.Identity,