on master help sign in
Merge pull request #2007 from david-christiansen/library-reorg

Initial reorganization into contrib

commit3d818586c3b674982c38627803388b9e4ded743f authorDavid Christiansen <david@davidchristiansen.dk> dateFri 20 Mar 2015, 10:17 (12 years ago) parent6592eacc2b1627
50 files changed+519−417
.gitignore+1 CHANGELOG+3 CONTRIBUTING.md+11−9 idris.cabal+9−3 libs/Makefile+10−5 libs/base/base.ipkg+7−14 libs/contrib/Classes/Verified.idr+114 libs/contrib/Control/Algebra.idr+274 libs/base/Control/Isomorphism/Primitives.idr → libs/contrib/Control/Isomorphism/Primitives.idr libs/base/Data/BoundedList.idr → libs/contrib/Data/BoundedList.idr libs/base/Data/Buffer.idr → libs/contrib/Data/Buffer.idr libs/base/Data/Fun.idr → libs/contrib/Data/Fun.idr libs/base/Data/Hash.idr → libs/contrib/Data/Hash.idr libs/base/Data/Heap.idr → libs/contrib/Data/Heap.idr+1−3 libs/base/Data/Matrix.idr → libs/contrib/Data/Matrix.idr+2−8 libs/base/Data/Rel.idr → libs/contrib/Data/Rel.idr libs/base/Data/Sign.idr → libs/contrib/Data/Sign.idr libs/base/Data/SortedMap.idr → libs/contrib/Data/SortedMap.idr libs/contrib/Data/SortedSet.idr+28 libs/base/Data/ZZ.idr → libs/contrib/Data/ZZ.idr libs/base/Decidable/Decidable.idr → libs/contrib/Decidable/Decidable.idr libs/base/Decidable/Order.idr → libs/contrib/Decidable/Order.idr libs/contrib/Makefile+24 libs/base/Network/Cgi.idr → libs/contrib/Network/Cgi.idr libs/base/Network/Socket.idr → libs/contrib/Network/Socket.idr libs/base/System/Concurrency/Process.idr → libs/contrib/System/Concurrency/Process.idr libs/contrib/contrib.ipkg+18 libs/prelude/Decidable/Equality.idr−9 libs/prelude/Prelude.idr+1−1 libs/prelude/Prelude/Algebra.idr−294 libs/prelude/Prelude/Applicative.idr−11 libs/prelude/Prelude/Functor.idr−6 libs/prelude/Prelude/List.idr−6 libs/prelude/Prelude/Monad.idr−10 libs/prelude/Prelude/Nat.idr−12 libs/base/Providers.idr → libs/prelude/Prelude/Providers.idr+5−1 libs/prelude/prelude.ipkg+1−1 src/Idris/Elab/Provider.hs+1−1 src/Idris/Providers.hs+3−3 test/basic011/run+1−1 test/docs002/docs002.idr−3 test/ffi002/expected+1−1 test/ffi002/test023.idr−2 test/ffi004/test026.idr−2 test/ffi005/Postulate.idr−2 test/interactive007/run+1−1 test/io003/run+2−2 test/primitives003/expected−2 test/primitives003/test038.idr−3 test/reg048/run+1−1
.gitignore+1
@@ -20,6 +20,7 @@ custom.mk
2020libs/base/base_doc/
2121libs/effects/effects_doc/
2222libs/prelude/prelude_doc/
23+libs/contrib/contrib_doc/
2324test/output
2425test/*[0-9][0-9][0-9]/output
2526test/*[0-9][0-9][0-9]/*.exe
CHANGELOG+3
@@ -40,6 +40,9 @@ New in 0.9.17:
4040* Classes can now be annotated with 'determining parameters' to say which
4141 must be available before resolving instances. Only determining parameters
4242 are checked when checking for overlapping instances.
43+* New package 'contrib' containing things that are less mature or less used
44+ than the contents of 'base'. 'contrib' is not available by default, so you
45+ may need to add '-p contrib' to your .ipkg file or Idris command line.
4346* Arguments to class instances are now checked for injectivity.
4447 Unification assumes this, so we need to check when instances are defined.
4548
CONTRIBUTING.md+11−9
@@ -9,7 +9,7 @@ Here are a few guidelines that we would like contributors to follow so that we c
991. Make sure you are familiar with [Git](http://git-scm.com/book).
10101. Make sure you have a [GitHub account](https://github.com/signup/free).
11111. Make sure you are familiar with: [Idris](http://eb.host.cs.st-andrews.ac.uk/writings/idris-tutorial.pdf).
12−1. Make sure you can install `Idris`:
12+1. Make sure you can install Idris:
1313 * [Mac OS X](https://github.com/idris-lang/Idris-dev/wiki/Idris-on-OS-X-using-Homebrew)
1414 * [Ubuntu](https://github.com/idris-lang/Idris-dev/wiki/Idris-on-Ubuntu)
1515 * [Debian](https://github.com/idris-lang/Idris-dev/wiki/Idris-on-Debian)
@@ -27,18 +27,20 @@ Please clean up any messes that you find, and don't leave behind new messes for
2727
2828## Contributing to the default libraries.
2929
30−`Idris` ships with a set of packages in `libs/` that is provided as a default library.
30+Idris ships with a set of packages in `libs/` that is provided as a default library.
3131These packages should not be seen as the *standard* as when working with dependent types we do not necessarily know how best to work with dependent types.
32−These packages offer functionality that can be built on top of when constructing `Idris` programs.
32+These packages offer functionality that can be built on top of when constructing Idris programs.
3333
3434One major point to make is that everything in prelude will be imported automatically, unless given
3535the `--noprelude` option.
36−A central idea within the `Idris` Community is that what counts as `Idris` is: **the compiler plus the Standard Prelude**.
37−Other libraries (base, effects, etc) are still part of the distribution, but not necessarily standard.
36+Likewise, the contents of base are available with no special options.
37+The other two packages that ship with Idris, contrib and effects, require a the use of the `-p` command-line argument to bring their contents into the include path.
38+New contributions should probably be sent to contrib first, so that they can get maintained with the Idris distribution.
39+If they turn out to be widely applicable and useful, they may later be moved into base.
3840
39−As `Idris` is still being developed we are open to suggestions and changes that make improvements to these default packages.
40−Major changes to the library (or `Idris` itself) should ideally be discussed first through the projects official channels of communication i.e. the mailing list, github wiki, or IRC, or as a [Dragon Egg](https://github.com/idris-lang/Idris-dev/wiki/Feature-proposals).
41−Developers then seeking to add content to `Idris`s prelude and default library, should do so through a PR where more discussion's and refinements can be made.
41+As Idris is still being developed we are open to suggestions and changes that make improvements to these default packages.
42+Major changes to the library (or Idris itself) should ideally be discussed first through the projects official channels of communication i.e. the mailing list, github wiki, or IRC, or as a [Dragon Egg](https://github.com/idris-lang/Idris-dev/wiki/Feature-proposals).
43+Developers then seeking to add content to Idris's prelude and default library, should do so through a PR where more discussion's and refinements can be made.
4244
4345We do not want you wasting your time nor duplicating somebody's work!
4446
@@ -140,7 +142,7 @@ To help increase the chance of your pull request being accepted:
140142
1411431. Run the tests.
1421441. Update the documentation, the surrounding one, examples elsewhere, guides, whatever is affected by your contribution
143−1. Use appropriate code formatting for both `Idris` and `Haskell`.
145+1. Use appropriate code formatting for both Idris and Haskell.
144146
145147## Additional Resources
146148
idris.cabal+9−3
@@ -99,19 +99,25 @@ Extra-source-files:
9999 libs/base/base.ipkg
100100 libs/base/*.idr
101101 libs/base/Control/*.idr
102− libs/base/Control/Isomorphism/*.idr
103102 libs/base/Control/Monad/*.idr
104103 libs/base/Data/*.idr
105104 libs/base/Data/Vect/*.idr
106105 libs/base/Debug/*.idr
107− libs/base/Decidable/*.idr
108106 libs/base/Language/Reflection/*.idr
109107 libs/base/Makefile
110− libs/base/Network/*.idr
111108 libs/base/System/*.idr
112109 libs/base/System/Concurrency/*.idr
113110 libs/base/Syntax/*.idr
114111
112+ libs/contrib/contrib.ipkg
113+ libs/contrib/Makefile
114+ libs/contrib/Classes/*.idr
115+ libs/contrib/Control/*.idr
116+ libs/contrib/Control/Isomorphism/*.idr
117+ libs/contrib/Data/*.idr
118+ libs/contrib/Decidable/*.idr
119+ libs/contrib/Network/*.idr
120+ libs/contrib/System/Concurrency/*.idr
115121
116122 libs/effects/Makefile
117123 libs/effects/effects.ipkg
libs/Makefile+10−5
@@ -1,28 +1,33 @@
11build:
22 $(MAKE) -C prelude build
33 $(MAKE) -C base build
4+ $(MAKE) -C contrib build
45 $(MAKE) -C effects build
56
67
78install:
89 $(MAKE) -C prelude install
910 $(MAKE) -C base install
11+ $(MAKE) -C contrib install
1012 $(MAKE) -C effects install
1113
1214clean:
1315 $(MAKE) -C prelude clean
1416 $(MAKE) -C base clean
17+ $(MAKE) -C contrib clean
1518 $(MAKE) -C effects clean
1619
1720doc:
18− $(MAKE) -C prelude doc
19− $(MAKE) -C base doc
20− $(MAKE) -C effects doc
21+ $(MAKE) -C prelude doc
22+ $(MAKE) -C base doc
23+ $(MAKE) -C contrib doc
24+ $(MAKE) -C effects doc
2125
2226doc_clean:
2327 $(MAKE) -C prelude doc_clean
24− $(MAKE) -C base doc_clean
25− $(MAKE) -C effects doc_clean
28+ $(MAKE) -C base doc_clean
29+ $(MAKE) -C contrib doc_clean
30+ $(MAKE) -C effects doc_clean
2631
2732
2833.PHONY: build install clean doc doc_clean
libs/base/base.ipkg+7−14
@@ -3,15 +3,9 @@ package base
33opts = "--nobasepkgs --total -i ../prelude"
44modules = System,
55
6− Network.Cgi, Network.Socket,
76 Debug.Error, Debug.Trace,
87
98 System.Info,
10− System.Concurrency.Raw, System.Concurrency.Process,
11−
12− Decidable.Decidable, Decidable.Order,
13−
14− Providers,
159
1610 Language.Reflection.Utils,
1711
@@ -19,20 +13,19 @@ modules = System,
1913
2014 Data.Morphisms,
2115 Data.Bits, Data.Mod2,
22− Data.ZZ, Data.Sign,
23− Data.SortedMap, Data.SortedSet, Data.BoundedList,
24− Data.Fin, Data.Vect, Data.VectType,
16+ Data.Fin, Data.Vect, Data.VectType,
2517 Data.HVect, Data.Vect.Quantifiers,
26− Data.Floats, Data.Complex, Data.Heap, Data.Fun,
27− Data.Rel, Data.Buffer, Data.Erased,
28− Data.List, Data.Hash, Data.Matrix,
18+ Data.Floats, Data.Complex,
19+ Data.Erased, Data.List,
2920 Data.So,
3021
31− Control.Isomorphism, Control.Isomorphism.Primitives,
22+ Control.Isomorphism,
3223 Control.Monad.Identity,
3324 Control.Monad.RWS,
3425 Control.Monad.Trans,
3526 Control.Monad.State, Control.Monad.Writer, Control.Monad.Reader,
3627 Control.Category, Control.Arrow,
37− Control.Catchable, Control.IOExcept
28+ Control.Catchable, Control.IOExcept,
29+
30+ System.Concurrency.Raw
3831
libs/contrib/Classes/Verified.idrnew file+114
@@ -0,0 +1,114 @@
1+module Classes.Verified
2+
3+import Control.Algebra
4+
5+-- Due to these being basically unused and difficult to implement,
6+-- they're in contrib for a bit. Once a design is found that lets them
7+-- be implemented for a number of instances, and we get those
8+-- implementations, then some of them can move back to base (or even
9+-- prelude, in the cases of Functor, Applicative, Monad, Semigroup,
10+-- and Monoid).
11+
12+class Functor f => VerifiedFunctor (f : Type -> Type) where
13+ functorIdentity : {a : Type} -> (x : f a) -> map id x = id x
14+ functorComposition : {a : Type} -> {b : Type} -> (x : f a) ->
15+ (g1 : a -> b) -> (g2 : b -> c) ->
16+ map (g2 . g1) x = (map g2 . map g1) x
17+
18+
19+
20+class (Applicative f, VerifiedFunctor f) => VerifiedApplicative (f : Type -> Type) where
21+ applicativeMap : (x : f a) -> (g : a -> b) ->
22+ map g x = pure g <*> x
23+ applicativeIdentity : (x : f a) -> pure id <*> x = x
24+ applicativeComposition : (x : f a) -> (g1 : f (a -> b)) -> (g2 : f (b -> c)) ->
25+ ((pure (.) <*> g2) <*> g1) <*> x = g2 <*> (g1 <*> x)
26+ applicativeHomomorphism : (x : a) -> (g : a -> b) ->
27+ (<*>) {f} (pure g) (pure x) = pure {f} (g x)
28+ applicativeInterchange : (x : a) -> (g : f (a -> b)) ->
29+ g <*> pure x = pure (\g' : a -> b => g' x) <*> g
30+
31+
32+class (Monad m, VerifiedApplicative m) => VerifiedMonad (m : Type -> Type) where
33+ monadApplicative : (mf : m (a -> b)) -> (mx : m a) ->
34+ mf <*> mx = mf >>= \f =>
35+ mx >>= \x =>
36+ pure (f x)
37+ monadLeftIdentity : (x : a) -> (f : a -> m b) -> return x >>= f = f x
38+ monadRightIdentity : (mx : m a) -> mx >>= return = mx
39+ monadAssociativity : (mx : m a) -> (f : a -> m b) -> (g : b -> m c) ->
40+ (mx >>= f) >>= g = mx >>= (\x => f x >>= g)
41+
42+
43+class Semigroup a => VerifiedSemigroup a where
44+ total semigroupOpIsAssociative : (l, c, r : a) -> l <+> (c <+> r) = (l <+> c) <+> r
45+
46+instance VerifiedSemigroup (List a) where
47+ semigroupOpIsAssociative = appendAssociative
48+
49+--instance VerifiedSemigroup Nat where
50+-- semigroupOpIsAssociative = plusAssociative
51+
52+
53+class (VerifiedSemigroup a, Monoid a) => VerifiedMonoid a where
54+ total monoidNeutralIsNeutralL : (l : a) -> l <+> neutral = l
55+ total monoidNeutralIsNeutralR : (r : a) -> neutral <+> r = r
56+
57+-- instance VerifiedMonoid Nat where
58+-- monoidNeutralIsNeutralL = plusZeroRightNeutral
59+-- monoidNeutralIsNeutralR = plusZeroLeftNeutral
60+
61+instance VerifiedMonoid (List a) where
62+ monoidNeutralIsNeutralL = appendNilRightNeutral
63+ monoidNeutralIsNeutralR xs = Refl
64+
65+class (VerifiedMonoid a, Group a) => VerifiedGroup a where
66+ total groupInverseIsInverseL : (l : a) -> l <+> inverse l = neutral
67+ total groupInverseIsInverseR : (r : a) -> inverse r <+> r = neutral
68+
69+class (VerifiedGroup a, AbelianGroup a) => VerifiedAbelianGroup a where
70+ total abelianGroupOpIsCommutative : (l, r : a) -> l <+> r = r <+> l
71+
72+class (VerifiedAbelianGroup a, Ring a) => VerifiedRing a where
73+ total ringOpIsAssociative : (l, c, r : a) -> l <.> (c <.> r) = (l <.> c) <.> r
74+ total ringOpIsDistributiveL : (l, c, r : a) -> l <.> (c <+> r) = (l <.> c) <+> (l <.> r)
75+ total ringOpIsDistributiveR : (l, c, r : a) -> (l <+> c) <.> r = (l <.> r) <+> (c <.> r)
76+
77+class (VerifiedRing a, RingWithUnity a) => VerifiedRingWithUnity a where
78+ total ringWithUnityIsUnityL : (l : a) -> l <.> unity = l
79+ total ringWithUnityIsUnityR : (r : a) -> unity <.> r = r
80+
81+class JoinSemilattice a => VerifiedJoinSemilattice a where
82+ total joinSemilatticeJoinIsAssociative : (l, c, r : a) -> join l (join c r) = join (join l c) r
83+ total joinSemilatticeJoinIsCommutative : (l, r : a) -> join l r = join r l
84+ total joinSemilatticeJoinIsIdempotent : (e : a) -> join e e = e
85+
86+class MeetSemilattice a => VerifiedMeetSemilattice a where
87+ total meetSemilatticeMeetIsAssociative : (l, c, r : a) -> meet l (meet c r) = meet (meet l c) r
88+ total meetSemilatticeMeetIsCommutative : (l, r : a) -> meet l r = meet r l
89+ total meetSemilatticeMeetIsIdempotent : (e : a) -> meet e e = e
90+
91+class (VerifiedJoinSemilattice a, BoundedJoinSemilattice a) => VerifiedBoundedJoinSemilattice a where
92+ total boundedJoinSemilatticeBottomIsBottom : (e : a) -> join e bottom = e
93+
94+class (VerifiedMeetSemilattice a, BoundedMeetSemilattice a) => VerifiedBoundedMeetSemilattice a where
95+ total boundedMeetSemilatticeTopIsTop : (e : a) -> meet e top = e
96+
97+class (VerifiedJoinSemilattice a, VerifiedMeetSemilattice a) => VerifiedLattice a where
98+ total latticeMeetAbsorbsJoin : (l, r : a) -> meet l (join l r) = l
99+ total latticeJoinAbsorbsMeet : (l, r : a) -> join l (meet l r) = l
100+
101+class (VerifiedBoundedJoinSemilattice a, VerifiedBoundedMeetSemilattice a, VerifiedLattice a) => VerifiedBoundedLattice a where { }
102+
103+class (VerifiedRing a, Field a) => VerifiedField a where
104+ total fieldInverseIsInverseL : (l : a) -> l <.> inverseM l = unity
105+ total fieldInverseIsInverseR : (r : a) -> inverseM r <.> r = unity
106+
107+-- class (VerifiedRingWithUnity a, VerifiedAbelianGroup b, Module a b) => VerifiedModule a b where
108+-- total moduleScalarMultiplyComposition : (x,y : a) -> (v : b) -> x <#> (y <#> v) = (x <.> y) <#> v
109+-- total moduleScalarUnityIsUnity : (v : b) -> unity <#> v = v
110+-- total moduleScalarMultDistributiveWRTVectorAddition : (s : a) -> (v, w : b) -> s <#> (v <+> w) = (s <#> v) <+> (s <#> w)
111+-- total moduleScalarMultDistributiveWRTModuleAddition : (s, t : a) -> (v : b) -> (s <+> t) <#> v = (s <#> v) <+> (t <#> v)
112+
113+-- class (VerifiedField a, VerifiedModule a b) => VerifiedVectorSpace a b where {}
114+
libs/contrib/Control/Algebra.idrnew file+274
@@ -0,0 +1,274 @@
1+module Control.Algebra
2+
3+import Data.Heap
4+
5+-- XXX: change?
6+infixl 6 <->
7+infixl 6 <.>
8+infixl 5 <#>
9+
10+||| Sets equipped with a single binary operation that is associative, along with
11+||| a neutral element for that binary operation and inverses for all elements.
12+||| Must satisfy the following laws:
13+||| + Associativity of `<+>`:
14+||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
15+||| + Neutral for `<+>`:
16+||| forall a, a <+> neutral == a
17+||| forall a, neutral <+> a == a
18+||| + Inverse for `<+>`:
19+||| forall a, a <+> inverse a == neutral
20+||| forall a, inverse a <+> a == neutral
21+class Monoid a => Group a where
22+ inverse : a -> a
23+
24+(<->) : Group a => a -> a -> a
25+(<->) left right = left <+> (inverse right)
26+
27+||| Sets equipped with a single binary operation that is associative and
28+||| commutative, along with a neutral element for that binary operation and
29+||| inverses for all elements. Must satisfy the following laws:
30+|||
31+||| + Associativity of `<+>`:
32+||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
33+||| + Commutativity of `<+>`:
34+||| forall a b, a <+> b == b <+> a
35+||| + Neutral for `<+>`:
36+||| forall a, a <+> neutral == a
37+||| forall a, neutral <+> a == a
38+||| + Inverse for `<+>`:
39+||| forall a, a <+> inverse a == neutral
40+||| forall a, inverse a <+> a == neutral
41+class Group a => AbelianGroup a where { }
42+
43+
44+||| Sets equipped with two binary operations, one associative and commutative
45+||| supplied with a neutral element, and the other associative, with
46+||| distributivity laws relating the two operations. Must satisfy the following
47+||| laws:
48+|||
49+||| + Associativity of `<+>`:
50+||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
51+||| + Commutativity of `<+>`:
52+||| forall a b, a <+> b == b <+> a
53+||| + Neutral for `<+>`:
54+||| forall a, a <+> neutral == a
55+||| forall a, neutral <+> a == a
56+||| + Inverse for `<+>`:
57+||| forall a, a <+> inverse a == neutral
58+||| forall a, inverse a <+> a == neutral
59+||| + Associativity of `<.>`:
60+||| forall a b c, a <.> (b <.> c) == (a <.> b) <.> c
61+||| + Distributivity of `<.>` and `<->`:
62+||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c)
63+||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c)
64+class AbelianGroup a => Ring a where
65+ (<.>) : a -> a -> a
66+
67+
68+||| Sets equipped with two binary operations, one associative and commutative
69+||| supplied with a neutral element, and the other associative supplied with a
70+||| neutral element, with distributivity laws relating the two operations. Must
71+||| satisfy the following laws:
72+|||
73+||| + Associativity of `<+>`:
74+||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
75+||| + Commutativity of `<+>`:
76+||| forall a b, a <+> b == b <+> a
77+||| + Neutral for `<+>`:
78+||| forall a, a <+> neutral == a
79+||| forall a, neutral <+> a == a
80+||| + Inverse for `<+>`:
81+||| forall a, a <+> inverse a == neutral
82+||| forall a, inverse a <+> a == neutral
83+||| + Associativity of `<.>`:
84+||| forall a b c, a <.> (b <.> c) == (a <.> b) <.> c
85+||| + Neutral for `<.>`:
86+||| forall a, a <.> unity == a
87+||| forall a, unity <.> a == a
88+||| + Distributivity of `<.>` and `<->`:
89+||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c)
90+||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c)
91+class Ring a => RingWithUnity a where
92+ unity : a
93+
94+
95+||| Sets equipped with a binary operation that is commutative, associative and
96+||| idempotent. Must satisfy the following laws:
97+|||
98+||| + Associativity of join:
99+||| forall a b c, join a (join b c) == join (join a b) c
100+||| + Commutativity of join:
101+||| forall a b, join a b == join b a
102+||| + Idempotency of join:
103+||| forall a, join a a == a
104+|||
105+||| Join semilattices capture the notion of sets with a "least upper bound".
106+class JoinSemilattice a where
107+ join : a -> a -> a
108+
109+instance JoinSemilattice Nat where
110+ join = maximum
111+
112+instance Ord a => JoinSemilattice (MaxiphobicHeap a) where
113+ join = merge
114+
115+||| Sets equipped with a binary operation that is commutative, associative and
116+||| idempotent. Must satisfy the following laws:
117+|||
118+||| + Associativity of meet:
119+||| forall a b c, meet a (meet b c) == meet (meet a b) c
120+||| + Commutativity of meet:
121+||| forall a b, meet a b == meet b a
122+||| + Idempotency of meet:
123+||| forall a, meet a a == a
124+|||
125+||| Meet semilattices capture the notion of sets with a "greatest lower bound".
126+class MeetSemilattice a where
127+ meet : a -> a -> a
128+
129+instance MeetSemilattice Nat where
130+ meet = minimum
131+
132+
133+||| Sets equipped with a binary operation that is commutative, associative and
134+||| idempotent and supplied with a unitary element. Must satisfy the following
135+||| laws:
136+|||
137+||| + Associativity of join:
138+||| forall a b c, join a (join b c) == join (join a b) c
139+||| + Commutativity of join:
140+||| forall a b, join a b == join b a
141+||| + Idempotency of join:
142+||| forall a, join a a == a
143+||| + Bottom (Unitary Element):
144+||| forall a, join a bottom == a
145+|||
146+||| Join semilattices capture the notion of sets with a "least upper bound"
147+||| equipped with a "bottom" element.
148+class JoinSemilattice a => BoundedJoinSemilattice a where
149+ bottom : a
150+
151+
152+instance BoundedJoinSemilattice Nat where
153+ bottom = Z
154+
155+
156+||| Sets equipped with a binary operation that is commutative, associative and
157+||| idempotent and supplied with a unitary element. Must satisfy the following
158+||| laws:
159+|||
160+||| + Associativity of meet:
161+||| forall a b c, meet a (meet b c) == meet (meet a b) c
162+||| + Commutativity of meet:
163+||| forall a b, meet a b == meet b a
164+||| + Idempotency of meet:
165+||| forall a, meet a a == a
166+||| + Top (Unitary Element):
167+||| forall a, meet a top == a
168+|||
169+||| Meet semilattices capture the notion of sets with a "greatest lower bound"
170+||| equipped with a "top" element.
171+class MeetSemilattice a => BoundedMeetSemilattice a where
172+ top : a
173+
174+
175+
176+||| Sets equipped with two binary operations that are both commutative,
177+||| associative and idempotent, along with absorbtion laws for relating the two
178+||| binary operations. Must satisfy the following:
179+|||
180+||| + Associativity of meet and join:
181+||| forall a b c, meet a (meet b c) == meet (meet a b) c
182+||| forall a b c, join a (join b c) == join (join a b) c
183+||| + Commutativity of meet and join:
184+||| forall a b, meet a b == meet b a
185+||| forall a b, join a b == join b a
186+||| + Idempotency of meet and join:
187+||| forall a, meet a a == a
188+||| forall a, join a a == a
189+||| + Absorbtion laws for meet and join:
190+||| forall a b, meet a (join a b) == a
191+||| forall a b, join a (meet a b) == a
192+class (JoinSemilattice a, MeetSemilattice a) => Lattice a where { }
193+
194+
195+instance Lattice Nat where { }
196+
197+||| Sets equipped with two binary operations that are both commutative,
198+||| associative and idempotent and supplied with neutral elements, along with
199+||| absorbtion laws for relating the two binary operations. Must satisfy the
200+||| following:
201+|||
202+||| + Associativity of meet and join:
203+||| forall a b c, meet a (meet b c) == meet (meet a b) c
204+||| forall a b c, join a (join b c) == join (join a b) c
205+||| + Commutativity of meet and join:
206+||| forall a b, meet a b == meet b a
207+||| forall a b, join a b == join b a
208+||| + Idempotency of meet and join:
209+||| forall a, meet a a == a
210+||| forall a, join a a == a
211+||| + Absorbtion laws for meet and join:
212+||| forall a b, meet a (join a b) == a
213+||| forall a b, join a (meet a b) == a
214+||| + Neutral for meet and join:
215+||| forall a, meet a top == top
216+||| forall a, join a bottom == bottom
217+class (BoundedJoinSemilattice a, BoundedMeetSemilattice a) => BoundedLattice a where { }
218+
219+
220+-- Fields.
221+||| Sets equipped with two binary operations, both associative and commutative
222+||| supplied with a neutral element, with
223+||| distributivity laws relating the two operations. Must satisfy the following
224+||| laws:
225+|||
226+||| + Associativity of `<+>`:
227+||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
228+||| + Commutativity of `<+>`:
229+||| forall a b, a <+> b == b <+> a
230+||| + Neutral for `<+>`:
231+||| forall a, a <+> neutral == a
232+||| forall a, neutral <+> a == a
233+||| + Inverse for `<+>`:
234+||| forall a, a <+> inverse a == neutral
235+||| forall a, inverse a <+> a == neutral
236+||| + Associativity of `<.>`:
237+||| forall a b c, a <.> (b <.> c) == (a <.> b) <.> c
238+||| + Unity for `<.>`:
239+||| forall a, a <.> unity == a
240+||| forall a, unity <.> a == a
241+||| + InverseM of `<.>`:
242+||| forall a, a <.> inverseM a == unity
243+||| forall a, inverseM a <.> a == unity
244+||| + Distributivity of `<.>` and `<->`:
245+||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c)
246+||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c)
247+class RingWithUnity a => Field a where
248+ inverseM : a -> a
249+
250+
251+||| A module over a ring is an additive abelian group of 'vectors' endowed with a
252+||| scale operation multiplying vectors by ring elements, and distributivity laws
253+||| relating the scale operation to both ring addition and module addition.
254+||| Must satisfy the following laws:
255+|||
256+||| + Compatibility of scalar multiplication with ring multiplication:
257+||| forall a b v, a <#> (b <#> v) = (a <.> b) <#> v
258+||| + Ring unity is the identity element of scalar multiplication:
259+||| forall v, unity <#> v = v
260+||| + Distributivity of `<#>` and `<+>`:
261+||| forall a v w, a <#> (v <+> w) == (a <#> v) <+> (a <#> w)
262+||| forall a b v, (a <+> b) <#> v == (a <#> v) <+> (b <#> v)
263+class (RingWithUnity a, AbelianGroup b) => Module a b where
264+ (<#>) : a -> b -> b
265+
266+
267+||| A vector space is a module over a ring that is also a field
268+class (Field a, Module a b) => VectorSpace a b where {}
269+
270+
271+-- XXX todo:
272+-- Structures where "abs" make sense.
273+-- Euclidean domains, etc.
274+-- Where to put fromInteger and fromRational?
libs/base/Control/Isomorphism/Primitives.idr → libs/contrib/Control/Isomorphism/Primitives.idrrenamed

The content is the same.

libs/base/Data/BoundedList.idr → libs/contrib/Data/BoundedList.idrrenamed

The content is the same.

libs/base/Data/Buffer.idr → libs/contrib/Data/Buffer.idrrenamed

The content is the same.

libs/base/Data/Fun.idr → libs/contrib/Data/Fun.idrrenamed

The content is the same.

libs/base/Data/Hash.idr → libs/contrib/Data/Hash.idrrenamed

The content is the same.

libs/base/Data/Heap.idr → libs/contrib/Data/Heap.idrrenamed+1−3
@@ -5,6 +5,7 @@
55
66module Data.Heap
77
8+
89%default total
910%access public
1011
@@ -128,9 +129,6 @@ instance Ord a => Semigroup (MaxiphobicHeap a) where
128129instance Ord a => Monoid (MaxiphobicHeap a) where
129130 neutral = empty
130131
131−instance Ord a => JoinSemilattice (MaxiphobicHeap a) where
132− join = merge
133−
134132--------------------------------------------------------------------------------
135133-- Properties
136134--------------------------------------------------------------------------------
libs/base/Data/Matrix.idr → libs/contrib/Data/Matrix.idrrenamed+2−8
@@ -1,5 +1,7 @@
11module Data.Matrix
22
3+import Control.Algebra
4+
35import Data.Complex
46import Data.ZZ
57import Data.Fin
@@ -212,14 +214,6 @@ instance Semigroup Nat where
212214instance Monoid Nat where
213215 neutral = 0
214216
215−instance VerifiedSemigroup Nat where
216− semigroupOpIsAssociative = plusAssociative
217−
218−instance VerifiedMonoid Nat where
219− monoidNeutralIsNeutralL = plusZeroRightNeutral
220− monoidNeutralIsNeutralR = plusZeroLeftNeutral
221−
222−
223217instance Semigroup ZZ where
224218 (<+>) = (+)
225219
libs/base/Data/Rel.idr → libs/contrib/Data/Rel.idrrenamed

The content is the same.

libs/base/Data/Sign.idr → libs/contrib/Data/Sign.idrrenamed

The content is the same.

libs/base/Data/SortedMap.idr → libs/contrib/Data/SortedMap.idrrenamed

The content is the same.

libs/contrib/Data/SortedSet.idrnew file+28
@@ -0,0 +1,28 @@
1+module Data.SortedSet
2+
3+import Data.SortedMap
4+
5+-- TODO: add intersection, union, difference
6+
7+data SortedSet k = SetWrapper (Data.SortedMap.SortedMap k ())
8+
9+empty : SortedSet k
10+empty = SetWrapper Data.SortedMap.empty
11+
12+insert : Ord k => k -> SortedSet k -> SortedSet k
13+insert k (SetWrapper m) = SetWrapper (Data.SortedMap.insert k () m)
14+
15+delete : Ord k => k -> SortedSet k -> SortedSet k
16+delete k (SetWrapper m) = SetWrapper (Data.SortedMap.delete k m)
17+
18+contains : Ord k => k -> SortedSet k -> Bool
19+contains k (SetWrapper m) = isJust (Data.SortedMap.lookup k m)
20+
21+fromList : Ord k => List k -> SortedSet k
22+fromList l = SetWrapper (Data.SortedMap.fromList (map (\i => (i, ())) l))
23+
24+toList : SortedSet k -> List k
25+toList (SetWrapper m) = map (\(i, _) => i) (Data.SortedMap.toList m)
26+
27+instance Foldable SortedSet where
28+ foldr f e xs = foldr f e (Data.SortedSet.toList xs)
libs/base/Data/ZZ.idr → libs/contrib/Data/ZZ.idrrenamed

The content is the same.

libs/base/Decidable/Decidable.idr → libs/contrib/Decidable/Decidable.idrrenamed

The content is the same.

libs/base/Decidable/Order.idr → libs/contrib/Decidable/Order.idrrenamed

The content is the same.

libs/contrib/Makefilenew file+24
@@ -0,0 +1,24 @@
1+IDRIS := idris
2+PKG := contrib
3+
4+build:
5+ $(IDRIS) --build ${PKG}.ipkg
6+
7+install:
8+ $(IDRIS) --install ${PKG}.ipkg
9+
10+clean:
11+ $(IDRIS) --clean ${PKG}.ipkg
12+
13+rebuild: clean build
14+
15+doc:
16+ ${IDRIS} --mkdoc ${PKG}.ipkg
17+
18+doc_clean:
19+ rm -rf ${PKG}_doc
20+
21+linecount:
22+ find . -name '*.idr' | xargs wc -l
23+
24+.PHONY: build install clean rebuild linecount
libs/base/Network/Cgi.idr → libs/contrib/Network/Cgi.idrrenamed

The content is the same.

libs/base/Network/Socket.idr → libs/contrib/Network/Socket.idrrenamed

The content is the same.

libs/base/System/Concurrency/Process.idr → libs/contrib/System/Concurrency/Process.idrrenamed

The content is the same.

libs/contrib/contrib.ipkgnew file+18
@@ -0,0 +1,18 @@
1+package contrib
2+
3+opts = "--nobasepkgs --total -i ../prelude -i ../base"
4+modules = Control.Algebra,
5+ Control.Isomorphism.Primitives,
6+ Classes.Verified,
7+ Data.Fun, Data.Rel, Data.Buffer,
8+ Data.Hash, Data.Matrix,
9+ Data.ZZ, Data.Sign,
10+ Data.BoundedList,
11+ Data.Heap,
12+ Data.SortedMap, Data.SortedSet,
13+
14+ Decidable.Decidable, Decidable.Order,
15+
16+ Network.Cgi, Network.Socket,
17+
18+ System.Concurrency.Process
libs/prelude/Decidable/Equality.idr−9
@@ -181,15 +181,6 @@ instance DecEq Integer where
181181 primitiveEq = believe_me (Refl {x})
182182 postulate primitiveNotEq : x = y -> Void
183183
184−--------------------------------------------------------------------------------
185−-- Float
186−--------------------------------------------------------------------------------
187−
188−instance DecEq Float where
189− decEq x y = if x == y then Yes primitiveEq else No primitiveNotEq
190− where primitiveEq : x = y
191− primitiveEq = believe_me (Refl {x})
192− postulate primitiveNotEq : x = y -> Void
193184
194185--------------------------------------------------------------------------------
195186-- String
libs/prelude/Prelude.idr+1−1
@@ -23,7 +23,7 @@ import public Prelude.Bits
2323import public Prelude.Uninhabited
2424import public Prelude.Pairs
2525import public Prelude.Stream
26−
26+import public Prelude.Providers
2727import public Decidable.Equality
2828import public Language.Reflection
2929import public Language.Reflection.Errors
libs/prelude/Prelude/Algebra.idr−294
@@ -22,8 +22,6 @@ infixl 5 <#>
2222class Semigroup a where
2323 (<+>) : a -> a -> a
2424
25−class Semigroup a => VerifiedSemigroup a where
26− total semigroupOpIsAssociative : (l, c, r : a) -> l <+> (c <+> r) = (l <+> c) <+> r
2725
2826||| Sets equipped with a single binary operation that is associative, along with
2927||| a neutral element for that binary operation. Must satisfy the following
@@ -37,295 +35,3 @@ class Semigroup a => VerifiedSemigroup a where
3735class Semigroup a => Monoid a where
3836 neutral : a
3937
40−class (VerifiedSemigroup a, Monoid a) => VerifiedMonoid a where
41− total monoidNeutralIsNeutralL : (l : a) -> l <+> neutral = l
42− total monoidNeutralIsNeutralR : (r : a) -> neutral <+> r = r
43−
44−||| Sets equipped with a single binary operation that is associative, along with
45−||| a neutral element for that binary operation and inverses for all elements.
46−||| Must satisfy the following laws:
47−||| + Associativity of `<+>`:
48−||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
49−||| + Neutral for `<+>`:
50−||| forall a, a <+> neutral == a
51−||| forall a, neutral <+> a == a
52−||| + Inverse for `<+>`:
53−||| forall a, a <+> inverse a == neutral
54−||| forall a, inverse a <+> a == neutral
55−class Monoid a => Group a where
56− inverse : a -> a
57−
58−class (VerifiedMonoid a, Group a) => VerifiedGroup a where
59− total groupInverseIsInverseL : (l : a) -> l <+> inverse l = neutral
60− total groupInverseIsInverseR : (r : a) -> inverse r <+> r = neutral
61−
62−(<->) : Group a => a -> a -> a
63−(<->) left right = left <+> (inverse right)
64−
65−||| Sets equipped with a single binary operation that is associative and
66−||| commutative, along with a neutral element for that binary operation and
67−||| inverses for all elements. Must satisfy the following laws:
68−|||
69−||| + Associativity of `<+>`:
70−||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
71−||| + Commutativity of `<+>`:
72−||| forall a b, a <+> b == b <+> a
73−||| + Neutral for `<+>`:
74−||| forall a, a <+> neutral == a
75−||| forall a, neutral <+> a == a
76−||| + Inverse for `<+>`:
77−||| forall a, a <+> inverse a == neutral
78−||| forall a, inverse a <+> a == neutral
79−class Group a => AbelianGroup a where { }
80−
81−class (VerifiedGroup a, AbelianGroup a) => VerifiedAbelianGroup a where
82− total abelianGroupOpIsCommutative : (l, r : a) -> l <+> r = r <+> l
83−
84−||| Sets equipped with two binary operations, one associative and commutative
85−||| supplied with a neutral element, and the other associative, with
86−||| distributivity laws relating the two operations. Must satisfy the following
87−||| laws:
88−|||
89−||| + Associativity of `<+>`:
90−||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
91−||| + Commutativity of `<+>`:
92−||| forall a b, a <+> b == b <+> a
93−||| + Neutral for `<+>`:
94−||| forall a, a <+> neutral == a
95−||| forall a, neutral <+> a == a
96−||| + Inverse for `<+>`:
97−||| forall a, a <+> inverse a == neutral
98−||| forall a, inverse a <+> a == neutral
99−||| + Associativity of `<.>`:
100−||| forall a b c, a <.> (b <.> c) == (a <.> b) <.> c
101−||| + Distributivity of `<.>` and `<->`:
102−||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c)
103−||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c)
104−class AbelianGroup a => Ring a where
105− (<.>) : a -> a -> a
106−
107−class (VerifiedAbelianGroup a, Ring a) => VerifiedRing a where
108− total ringOpIsAssociative : (l, c, r : a) -> l <.> (c <.> r) = (l <.> c) <.> r
109− total ringOpIsDistributiveL : (l, c, r : a) -> l <.> (c <+> r) = (l <.> c) <+> (l <.> r)
110− total ringOpIsDistributiveR : (l, c, r : a) -> (l <+> c) <.> r = (l <.> r) <+> (c <.> r)
111−
112−||| Sets equipped with two binary operations, one associative and commutative
113−||| supplied with a neutral element, and the other associative supplied with a
114−||| neutral element, with distributivity laws relating the two operations. Must
115−||| satisfy the following laws:
116−|||
117−||| + Associativity of `<+>`:
118−||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
119−||| + Commutativity of `<+>`:
120−||| forall a b, a <+> b == b <+> a
121−||| + Neutral for `<+>`:
122−||| forall a, a <+> neutral == a
123−||| forall a, neutral <+> a == a
124−||| + Inverse for `<+>`:
125−||| forall a, a <+> inverse a == neutral
126−||| forall a, inverse a <+> a == neutral
127−||| + Associativity of `<.>`:
128−||| forall a b c, a <.> (b <.> c) == (a <.> b) <.> c
129−||| + Neutral for `<.>`:
130−||| forall a, a <.> unity == a
131−||| forall a, unity <.> a == a
132−||| + Distributivity of `<.>` and `<->`:
133−||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c)
134−||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c)
135−class Ring a => RingWithUnity a where
136− unity : a
137−
138−class (VerifiedRing a, RingWithUnity a) => VerifiedRingWithUnity a where
139− total ringWithUnityIsUnityL : (l : a) -> l <.> unity = l
140− total ringWithUnityIsUnityR : (r : a) -> unity <.> r = r
141−
142−||| Sets equipped with a binary operation that is commutative, associative and
143−||| idempotent. Must satisfy the following laws:
144−|||
145−||| + Associativity of join:
146−||| forall a b c, join a (join b c) == join (join a b) c
147−||| + Commutativity of join:
148−||| forall a b, join a b == join b a
149−||| + Idempotency of join:
150−||| forall a, join a a == a
151−|||
152−||| Join semilattices capture the notion of sets with a "least upper bound".
153−class JoinSemilattice a where
154− join : a -> a -> a
155−
156−class JoinSemilattice a => VerifiedJoinSemilattice a where
157− total joinSemilatticeJoinIsAssociative : (l, c, r : a) -> join l (join c r) = join (join l c) r
158− total joinSemilatticeJoinIsCommutative : (l, r : a) -> join l r = join r l
159− total joinSemilatticeJoinIsIdempotent : (e : a) -> join e e = e
160−
161−||| Sets equipped with a binary operation that is commutative, associative and
162−||| idempotent. Must satisfy the following laws:
163−|||
164−||| + Associativity of meet:
165−||| forall a b c, meet a (meet b c) == meet (meet a b) c
166−||| + Commutativity of meet:
167−||| forall a b, meet a b == meet b a
168−||| + Idempotency of meet:
169−||| forall a, meet a a == a
170−|||
171−||| Meet semilattices capture the notion of sets with a "greatest lower bound".
172−class MeetSemilattice a where
173− meet : a -> a -> a
174−
175−class MeetSemilattice a => VerifiedMeetSemilattice a where
176− total meetSemilatticeMeetIsAssociative : (l, c, r : a) -> meet l (meet c r) = meet (meet l c) r
177− total meetSemilatticeMeetIsCommutative : (l, r : a) -> meet l r = meet r l
178− total meetSemilatticeMeetIsIdempotent : (e : a) -> meet e e = e
179−
180−||| Sets equipped with a binary operation that is commutative, associative and
181−||| idempotent and supplied with a unitary element. Must satisfy the following
182−||| laws:
183−|||
184−||| + Associativity of join:
185−||| forall a b c, join a (join b c) == join (join a b) c
186−||| + Commutativity of join:
187−||| forall a b, join a b == join b a
188−||| + Idempotency of join:
189−||| forall a, join a a == a
190−||| + Bottom (Unitary Element):
191−||| forall a, join a bottom == a
192−|||
193−||| Join semilattices capture the notion of sets with a "least upper bound"
194−||| equipped with a "bottom" element.
195−class JoinSemilattice a => BoundedJoinSemilattice a where
196− bottom : a
197−
198−class (VerifiedJoinSemilattice a, BoundedJoinSemilattice a) => VerifiedBoundedJoinSemilattice a where
199− total boundedJoinSemilatticeBottomIsBottom : (e : a) -> join e bottom = e
200−
201−||| Sets equipped with a binary operation that is commutative, associative and
202−||| idempotent and supplied with a unitary element. Must satisfy the following
203−||| laws:
204−|||
205−||| + Associativity of meet:
206−||| forall a b c, meet a (meet b c) == meet (meet a b) c
207−||| + Commutativity of meet:
208−||| forall a b, meet a b == meet b a
209−||| + Idempotency of meet:
210−||| forall a, meet a a == a
211−||| + Top (Unitary Element):
212−||| forall a, meet a top == a
213−|||
214−||| Meet semilattices capture the notion of sets with a "greatest lower bound"
215−||| equipped with a "top" element.
216−class MeetSemilattice a => BoundedMeetSemilattice a where
217− top : a
218−
219−class (VerifiedMeetSemilattice a, BoundedMeetSemilattice a) => VerifiedBoundedMeetSemilattice a where
220− total boundedMeetSemilatticeTopIsTop : (e : a) -> meet e top = e
221−
222−||| Sets equipped with two binary operations that are both commutative,
223−||| associative and idempotent, along with absorbtion laws for relating the two
224−||| binary operations. Must satisfy the following:
225−|||
226−||| + Associativity of meet and join:
227−||| forall a b c, meet a (meet b c) == meet (meet a b) c
228−||| forall a b c, join a (join b c) == join (join a b) c
229−||| + Commutativity of meet and join:
230−||| forall a b, meet a b == meet b a
231−||| forall a b, join a b == join b a
232−||| + Idempotency of meet and join:
233−||| forall a, meet a a == a
234−||| forall a, join a a == a
235−||| + Absorbtion laws for meet and join:
236−||| forall a b, meet a (join a b) == a
237−||| forall a b, join a (meet a b) == a
238−class (JoinSemilattice a, MeetSemilattice a) => Lattice a where { }
239−
240−class (VerifiedJoinSemilattice a, VerifiedMeetSemilattice a) => VerifiedLattice a where
241− total latticeMeetAbsorbsJoin : (l, r : a) -> meet l (join l r) = l
242− total latticeJoinAbsorbsMeet : (l, r : a) -> join l (meet l r) = l
243−
244−||| Sets equipped with two binary operations that are both commutative,
245−||| associative and idempotent and supplied with neutral elements, along with
246−||| absorbtion laws for relating the two binary operations. Must satisfy the
247−||| following:
248−|||
249−||| + Associativity of meet and join:
250−||| forall a b c, meet a (meet b c) == meet (meet a b) c
251−||| forall a b c, join a (join b c) == join (join a b) c
252−||| + Commutativity of meet and join:
253−||| forall a b, meet a b == meet b a
254−||| forall a b, join a b == join b a
255−||| + Idempotency of meet and join:
256−||| forall a, meet a a == a
257−||| forall a, join a a == a
258−||| + Absorbtion laws for meet and join:
259−||| forall a b, meet a (join a b) == a
260−||| forall a b, join a (meet a b) == a
261−||| + Neutral for meet and join:
262−||| forall a, meet a top == top
263−||| forall a, join a bottom == bottom
264−class (BoundedJoinSemilattice a, BoundedMeetSemilattice a) => BoundedLattice a where { }
265−
266−class (VerifiedBoundedJoinSemilattice a, VerifiedBoundedMeetSemilattice a, VerifiedLattice a) => VerifiedBoundedLattice a where { }
267−
268−-- Fields.
269−||| Sets equipped with two binary operations, both associative and commutative
270−||| supplied with a neutral element, with
271−||| distributivity laws relating the two operations. Must satisfy the following
272−||| laws:
273−|||
274−||| + Associativity of `<+>`:
275−||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c
276−||| + Commutativity of `<+>`:
277−||| forall a b, a <+> b == b <+> a
278−||| + Neutral for `<+>`:
279−||| forall a, a <+> neutral == a
280−||| forall a, neutral <+> a == a
281−||| + Inverse for `<+>`:
282−||| forall a, a <+> inverse a == neutral
283−||| forall a, inverse a <+> a == neutral
284−||| + Associativity of `<.>`:
285−||| forall a b c, a <.> (b <.> c) == (a <.> b) <.> c
286−||| + Unity for `<.>`:
287−||| forall a, a <.> unity == a
288−||| forall a, unity <.> a == a
289−||| + InverseM of `<.>`:
290−||| forall a, a <.> inverseM a == unity
291−||| forall a, inverseM a <.> a == unity
292−||| + Distributivity of `<.>` and `<->`:
293−||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c)
294−||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c)
295−class RingWithUnity a => Field a where
296− inverseM : a -> a
297−
298−class (VerifiedRing a, Field a) => VerifiedField a where
299− total fieldInverseIsInverseL : (l : a) -> l <.> inverseM l = unity
300− total fieldInverseIsInverseR : (r : a) -> inverseM r <.> r = unity
301−
302−||| A module over a ring is an additive abelian group of 'vectors' endowed with a
303−||| scale operation multiplying vectors by ring elements, and distributivity laws
304−||| relating the scale operation to both ring addition and module addition.
305−||| Must satisfy the following laws:
306−|||
307−||| + Compatibility of scalar multiplication with ring multiplication:
308−||| forall a b v, a <#> (b <#> v) = (a <.> b) <#> v
309−||| + Ring unity is the identity element of scalar multiplication:
310−||| forall v, unity <#> v = v
311−||| + Distributivity of `<#>` and `<+>`:
312−||| forall a v w, a <#> (v <+> w) == (a <#> v) <+> (a <#> w)
313−||| forall a b v, (a <+> b) <#> v == (a <#> v) <+> (b <#> v)
314−class (RingWithUnity a, AbelianGroup b) => Module a b where
315− (<#>) : a -> b -> b
316−
317−class (VerifiedRingWithUnity a, VerifiedAbelianGroup b, Module a b) => VerifiedModule a b where
318− total moduleScalarMultiplyComposition : (x,y : a) -> (v : b) -> x <#> (y <#> v) = (x <.> y) <#> v
319− total moduleScalarUnityIsUnity : (v : b) -> unity {a} <#> v = v
320− total moduleScalarMultDistributiveWRTVectorAddition : (s : a) -> (v, w : b) -> s <#> (v <+> w) = (s <#> v) <+> (s <#> w)
321− total moduleScalarMultDistributiveWRTModuleAddition : (s, t : a) -> (v : b) -> (s <+> t) <#> v = (s <#> v) <+> (t <#> v)
322−
323−||| A vector space is a module over a ring that is also a field
324−class (Field a, Module a b) => VectorSpace a b where {}
325−
326−class (VerifiedField a, VerifiedModule a b) => VerifiedVectorSpace a b where {}
327−
328−-- XXX todo:
329−-- Structures where "abs" make sense.
330−-- Euclidean domains, etc.
331−-- Where to put fromInteger and fromRational?
libs/prelude/Prelude/Applicative.idr−11
@@ -15,17 +15,6 @@ class Functor f => Applicative (f : Type -> Type) where
1515 pure : a -> f a
1616 (<*>) : f (a -> b) -> f a -> f b
1717
18−class (Applicative f, VerifiedFunctor f) => VerifiedApplicative (f : Type -> Type) where
19− applicativeMap : (x : f a) -> (g : a -> b) ->
20− map g x = pure g <*> x
21− applicativeIdentity : (x : f a) -> pure id <*> x = x
22− applicativeComposition : (x : f a) -> (g1 : f (a -> b)) -> (g2 : f (b -> c)) ->
23− ((pure (.) <*> g2) <*> g1) <*> x = g2 <*> (g1 <*> x)
24− applicativeHomomorphism : (x : a) -> (g : a -> b) ->
25− (<*>) {f} (pure g) (pure x) = pure {f} (g x)
26− applicativeInterchange : (x : a) -> (g : f (a -> b)) ->
27− g <*> pure x = pure (\g' : a -> b => g' x) <*> g
28−
2918infixl 2 <*
3019(<*) : Applicative f => f a -> f b -> f a
3120a <* b = map const a <*> b
libs/prelude/Prelude/Functor.idr−6
@@ -18,9 +18,3 @@ infixl 4 <$>
1818(<$>) : Functor f => (m : a -> b) -> f a -> f b
1919m <$> x = map m x
2020
21−class Functor f => VerifiedFunctor (f : Type -> Type) where
22− functorIdentity : {a : Type} -> (x : f a) -> map id x = id x
23− functorComposition : {a : Type} -> {b : Type} -> (x : f a) ->
24− (g1 : a -> b) -> (g2 : b -> c) ->
25− map (g2 . g1) x = (map g2 . map g1) x
26−
libs/prelude/Prelude/List.idr−6
@@ -809,12 +809,6 @@ hasAnyByNilFalse p (x::xs) =
809809hasAnyNilFalse : Eq a => (l : List a) -> hasAny [] l = False
810810hasAnyNilFalse l = ?hasAnyNilFalseBody
811811
812−instance VerifiedSemigroup (List a) where
813− semigroupOpIsAssociative = appendAssociative
814−
815−instance VerifiedMonoid (List a) where
816− monoidNeutralIsNeutralL = appendNilRightNeutral
817− monoidNeutralIsNeutralR xs = Refl
818812
819813--------------------------------------------------------------------------------
820814-- Proofs
libs/prelude/Prelude/Monad.idr−10
@@ -14,16 +14,6 @@ infixl 5 >>=
1414class Applicative m => Monad (m : Type -> Type) where
1515 (>>=) : m a -> (a -> m b) -> m b
1616
17−class (Monad m, VerifiedApplicative m) => VerifiedMonad (m : Type -> Type) where
18− monadApplicative : (mf : m (a -> b)) -> (mx : m a) ->
19− mf <*> mx = mf >>= \f =>
20− mx >>= \x =>
21− pure (f x)
22− monadLeftIdentity : (x : a) -> (f : a -> m b) -> return x >>= f = f x
23− monadRightIdentity : (mx : m a) -> mx >>= return = mx
24− monadAssociativity : (mx : m a) -> (f : a -> m b) -> (g : b -> m c) ->
25− (mx >>= f) >>= g = mx >>= (\x => f x >>= g)
26−
2717||| Also called `join` or mu
2818flatten : Monad m => m (m a) -> m a
2919flatten a = a >>= id
libs/prelude/Prelude/Nat.idr−12
@@ -239,18 +239,6 @@ instance Monoid Multiplicative where
239239instance Monoid Additive where
240240 neutral = getAdditive Z
241241
242−instance MeetSemilattice Nat where
243− meet = minimum
244−
245−instance JoinSemilattice Nat where
246− join = maximum
247−
248−instance Lattice Nat where { }
249−
250−instance BoundedJoinSemilattice Nat where
251− bottom = Z
252−
253−
254242||| Casts negative `Ints` to 0.
255243instance Cast Int Nat where
256244 cast i = fromInteger (cast i)
libs/base/Providers.idr → libs/prelude/Prelude/Providers.idrrenamed+5−1
@@ -1,4 +1,8 @@
1−module Providers
1+module Prelude.Providers
2+
3+import Prelude.Functor
4+import Prelude.Applicative
5+import Prelude.Monad
26
37||| Type providers must build one of these in an IO computation.
48public
libs/prelude/prelude.ipkg+1−1
@@ -8,7 +8,7 @@ modules = Builtins, Prelude, IO,
88 Prelude.Maybe, Prelude.Monad, Prelude.Applicative, Prelude.Either,
99 Prelude.Strings, Prelude.Chars, Prelude.Functor,
1010 Prelude.Foldable, Prelude.Traversable, Prelude.Bits, Prelude.Stream,
11− Prelude.Uninhabited, Prelude.Pairs,
11+ Prelude.Uninhabited, Prelude.Pairs, Prelude.Providers,
1212
1313 Language.Reflection, Language.Reflection.Errors, Language.Reflection.Tactical,
1414
src/Idris/Elab/Provider.hs+1−1
@@ -112,7 +112,7 @@ elabProvider doc info syn fc what n
112112 -- error messages with less normalisation
113113 providerOf :: Type -> Type
114114 providerOf ty = App (P Ref (sUN "IO") Erased) $
115− App (P Ref (sNS (sUN "Provider") ["Providers"]) Erased)
115+ App (P Ref (sNS (sUN "Provider") ["Providers", "Prelude"]) Erased)
116116 ty
117117
118118 isProviderOf :: Context -> TT Name -> TT Name -> Bool
src/Idris/Providers.hs+3−3
@@ -10,16 +10,16 @@ import Idris.Error
1010-- | Wrap a type provider in the type of type providers
1111providerTy :: FC -> PTerm -> PTerm
1212providerTy fc tm
13− = PApp fc (PRef fc $ sUN "Provider") [PExp 0 [] (sMN 0 "pvarg") tm]
13+ = PApp fc (PRef fc $ sNS (sUN "Provider" ) ["Providers", "Prelude"]) [PExp 0 [] (sMN 0 "pvarg") tm]
1414
1515ioret :: Name
1616ioret = sUN "prim_io_return"
1717
1818ermod :: Name
19−ermod = sNS (sUN "Error") ["Providers"]
19+ermod = sNS (sUN "Error") ["Providers", "Prelude"]
2020
2121prmod :: Name
22−prmod = sNS (sUN "Provide") ["Providers"]
22+prmod = sNS (sUN "Provide") ["Providers", "Prelude"]
2323
2424data Provided a = Provide a
2525 deriving (Show, Eq, Functor)
test/basic011/run+1−1
@@ -1,4 +1,4 @@
11#!/usr/bin/env bash
2−idris $@ basic011.idr -o basic011
2+idris $@ basic011.idr -p contrib -o basic011
33./basic011
44rm -f basic011 *.ibc
test/docs002/docs002.idr−3
@@ -1,9 +1,6 @@
11module Main
22
33-- Simple test case for type provider documentation.
4−
5−import Providers
6−
74%language TypeProviders
85
96getType : Int -> IO (Provider Type)
test/ffi002/expected+1−1
@@ -1 +1 @@
1−test023.idr:22:21:Type provider error: Always fails
1+test023.idr:20:21:Type provider error: Always fails
test/ffi002/test023.idr−2
@@ -2,8 +2,6 @@ module Main
22
33-- Simple test case for trivial type providers.
44
5−import Providers
6−
75%language TypeProviders
86
97-- Provide the Unit type
test/ffi004/test026.idr−2
@@ -2,8 +2,6 @@ module Main
22
33-- Simple test case for trivial type providers.
44
5−import Providers
6−
75%language TypeProviders
86
97strToType : String -> Type
test/ffi005/Postulate.idr−2
@@ -1,7 +1,5 @@
11module Main
22
3−import Providers
4−
53%language TypeProviders
64
75bad : IO (Provider Type)
test/interactive007/run+1−1
@@ -1,2 +1,2 @@
11#!/usr/bin/env bash
2−idris --nobanner --nocolor < input
2+idris -p contrib --nobanner --nocolor < input
test/io003/run+2−2
@@ -1,6 +1,6 @@
11#!/usr/bin/env bash
2−idris $@ test018.idr -o test018
3−idris $@ test018a.idr -o test018a
2+idris $@ test018.idr -p contrib -o test018
3+idris $@ test018a.idr -p contrib -o test018a
44./test018
55#./test018a
66rm -f test018 test018a *.ibc
test/primitives003/expected−2
@@ -16,8 +16,6 @@ True
1616False
1717True
1818False
19−True
20−False
2119False
2220True
2321False
test/primitives003/test038.idr−3
@@ -40,9 +40,6 @@ main = do
4040 -- Booleans
4141 putStrLn . show $ test True True
4242 putStrLn . show $ test True False
43− -- Float
44− putStrLn . show $ test 1.0 1.0
45− putStrLn . show $ test 1.0 2.0
4643 -- Maybe
4744 putStrLn . show $ test (Just "hello") (Just "hello")
4845 putStrLn . show $ test (Just "hello") (Just "world")
test/reg048/run+1−1
@@ -1,4 +1,4 @@
11#!/usr/bin/env bash
2−idris $@ reg048.idr -o reg048
2+idris $@ reg048.idr -p contrib -o reg048
33./reg048
44rm -f reg048 *.ibc