on master help sign in
Merge pull request #2007 from david-christiansen/library-reorg
3d81858David Christiansen
.gitignore+1
@@ -20,6 +20,7 @@ custom.mk
20libs/base/base_doc/
20libs/base/base_doc/
21libs/effects/effects_doc/
21libs/effects/effects_doc/
22libs/prelude/prelude_doc/
22libs/prelude/prelude_doc/
23+libs/contrib/contrib_doc/
23test/output
24test/output
24test/*[0-9][0-9][0-9]/output
25test/*[0-9][0-9][0-9]/output
25test/*[0-9][0-9][0-9]/*.exe
26test/*[0-9][0-9][0-9]/*.exe
CHANGELOG+3
@@ -40,6 +40,9 @@ New in 0.9.17:
40* Classes can now be annotated with 'determining parameters' to say which
40* Classes can now be annotated with 'determining parameters' to say which
41 must be available before resolving instances. Only determining parameters
41 must be available before resolving instances. Only determining parameters
42 are checked when checking for overlapping instances.
42 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.
43* Arguments to class instances are now checked for injectivity.
46* Arguments to class instances are now checked for injectivity.
44 Unification assumes this, so we need to check when instances are defined.
47 Unification assumes this, so we need to check when instances are defined.
45
48
CONTRIBUTING.md+11−9
@@ -9,7 +9,7 @@ Here are a few guidelines that we would like contributors to follow so that we c
91. Make sure you are familiar with [Git](http://git-scm.com/book).
91. Make sure you are familiar with [Git](http://git-scm.com/book).
101. Make sure you have a [GitHub account](https://github.com/signup/free).
101. Make sure you have a [GitHub account](https://github.com/signup/free).
111. Make sure you are familiar with: [Idris](http://eb.host.cs.st-andrews.ac.uk/writings/idris-tutorial.pdf).
111. 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:
13 * [Mac OS X](https://github.com/idris-lang/Idris-dev/wiki/Idris-on-OS-X-using-Homebrew)
13 * [Mac OS X](https://github.com/idris-lang/Idris-dev/wiki/Idris-on-OS-X-using-Homebrew)
14 * [Ubuntu](https://github.com/idris-lang/Idris-dev/wiki/Idris-on-Ubuntu)
14 * [Ubuntu](https://github.com/idris-lang/Idris-dev/wiki/Idris-on-Ubuntu)
15 * [Debian](https://github.com/idris-lang/Idris-dev/wiki/Idris-on-Debian)
15 * [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
27
27
28## Contributing to the default libraries.
28## Contributing to the default libraries.
29
29
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.
31These 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.
31These 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.
33
33
34One major point to make is that everything in prelude will be imported automatically, unless given
34One major point to make is that everything in prelude will be imported automatically, unless given
35the `--noprelude` option.
35the `--noprelude` option.
36−A central idea within the `Idris` Community is that what counts as `Idris` is: **the compiler plus the Standard Prelude**.
36+Likewise, the contents of base are available with no special options.
37−Other libraries (base, effects, etc) are still part of the distribution, but not necessarily standard.
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.
38
40
39−As `Idris` is still being developed we are open to suggestions and changes that make improvements to these default packages.
41+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).
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).
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.
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.
42
44
43We do not want you wasting your time nor duplicating somebody's work!
45We do not want you wasting your time nor duplicating somebody's work!
44
46
@@ -140,7 +142,7 @@ To help increase the chance of your pull request being accepted:
140
142
1411. Run the tests.
1431. Run the tests.
1421. Update the documentation, the surrounding one, examples elsewhere, guides, whatever is affected by your contribution
1441. 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.
144
146
145## Additional Resources
147## Additional Resources
146
148
idris.cabal+9−3
@@ -99,19 +99,25 @@ Extra-source-files:
99 libs/base/base.ipkg
99 libs/base/base.ipkg
100 libs/base/*.idr
100 libs/base/*.idr
101 libs/base/Control/*.idr
101 libs/base/Control/*.idr
102− libs/base/Control/Isomorphism/*.idr
103 libs/base/Control/Monad/*.idr
102 libs/base/Control/Monad/*.idr
104 libs/base/Data/*.idr
103 libs/base/Data/*.idr
105 libs/base/Data/Vect/*.idr
104 libs/base/Data/Vect/*.idr
106 libs/base/Debug/*.idr
105 libs/base/Debug/*.idr
107− libs/base/Decidable/*.idr
108 libs/base/Language/Reflection/*.idr
106 libs/base/Language/Reflection/*.idr
109 libs/base/Makefile
107 libs/base/Makefile
110− libs/base/Network/*.idr
111 libs/base/System/*.idr
108 libs/base/System/*.idr
112 libs/base/System/Concurrency/*.idr
109 libs/base/System/Concurrency/*.idr
113 libs/base/Syntax/*.idr
110 libs/base/Syntax/*.idr
114
111
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
115
121
116 libs/effects/Makefile
122 libs/effects/Makefile
117 libs/effects/effects.ipkg
123 libs/effects/effects.ipkg
libs/Makefile+10−5
@@ -1,28 +1,33 @@
1build:
1build:
2 $(MAKE) -C prelude build
2 $(MAKE) -C prelude build
3 $(MAKE) -C base build
3 $(MAKE) -C base build
4+ $(MAKE) -C contrib build
4 $(MAKE) -C effects build
5 $(MAKE) -C effects build
5
6
6
7
7install:
8install:
8 $(MAKE) -C prelude install
9 $(MAKE) -C prelude install
9 $(MAKE) -C base install
10 $(MAKE) -C base install
11+ $(MAKE) -C contrib install
10 $(MAKE) -C effects install
12 $(MAKE) -C effects install
11
13
12clean:
14clean:
13 $(MAKE) -C prelude clean
15 $(MAKE) -C prelude clean
14 $(MAKE) -C base clean
16 $(MAKE) -C base clean
17+ $(MAKE) -C contrib clean
15 $(MAKE) -C effects clean
18 $(MAKE) -C effects clean
16
19
17doc:
20doc:
18− $(MAKE) -C prelude doc
21+ $(MAKE) -C prelude doc
19− $(MAKE) -C base doc
22+ $(MAKE) -C base doc
23+ $(MAKE) -C contrib doc
20− $(MAKE) -C effects doc
24+ $(MAKE) -C effects doc
21
25
22doc_clean:
26doc_clean:
23 $(MAKE) -C prelude doc_clean
27 $(MAKE) -C prelude doc_clean
24− $(MAKE) -C base doc_clean
28+ $(MAKE) -C base doc_clean
29+ $(MAKE) -C contrib doc_clean
25− $(MAKE) -C effects doc_clean
30+ $(MAKE) -C effects doc_clean
26
31
27
32
28.PHONY: build install clean doc doc_clean
33.PHONY: build install clean doc doc_clean
libs/base/base.ipkg+7−14
@@ -3,15 +3,9 @@ package base
3opts = "--nobasepkgs --total -i ../prelude"
3opts = "--nobasepkgs --total -i ../prelude"
4modules = System,
4modules = System,
5
5
6− Network.Cgi, Network.Socket,
7 Debug.Error, Debug.Trace,
6 Debug.Error, Debug.Trace,
8
7
9 System.Info,
8 System.Info,
10− System.Concurrency.Raw, System.Concurrency.Process,
11−
12− Decidable.Decidable, Decidable.Order,
13−
14− Providers,
15
9
16 Language.Reflection.Utils,
10 Language.Reflection.Utils,
17
11
@@ -19,20 +13,19 @@ modules = System,
19
13
20 Data.Morphisms,
14 Data.Morphisms,
21 Data.Bits, Data.Mod2,
15 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,
25 Data.HVect, Data.Vect.Quantifiers,
17 Data.HVect, Data.Vect.Quantifiers,
26− Data.Floats, Data.Complex, Data.Heap, Data.Fun,
18+ Data.Floats, Data.Complex,
27− Data.Rel, Data.Buffer, Data.Erased,
19+ Data.Erased, Data.List,
28− Data.List, Data.Hash, Data.Matrix,
29 Data.So,
20 Data.So,
30
21
31− Control.Isomorphism, Control.Isomorphism.Primitives,
22+ Control.Isomorphism,
32 Control.Monad.Identity,
23 Control.Monad.Identity,
33 Control.Monad.RWS,
24 Control.Monad.RWS,
34 Control.Monad.Trans,
25 Control.Monad.Trans,
35 Control.Monad.State, Control.Monad.Writer, Control.Monad.Reader,
26 Control.Monad.State, Control.Monad.Writer, Control.Monad.Reader,
36 Control.Category, Control.Arrow,
27 Control.Category, Control.Arrow,
37− Control.Catchable, Control.IOExcept
28+ Control.Catchable, Control.IOExcept,
29+
30+ System.Concurrency.Raw
38
31
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 @@
5
5
6module Data.Heap
6module Data.Heap
7
7
8+
8%default total
9%default total
9%access public
10%access public
10
11
@@ -128,9 +129,6 @@ instance Ord a => Semigroup (MaxiphobicHeap a) where
128instance Ord a => Monoid (MaxiphobicHeap a) where
129instance Ord a => Monoid (MaxiphobicHeap a) where
129 neutral = empty
130 neutral = empty
130
131
131−instance Ord a => JoinSemilattice (MaxiphobicHeap a) where
132− join = merge
133−
134--------------------------------------------------------------------------------
132--------------------------------------------------------------------------------
135-- Properties
133-- Properties
136--------------------------------------------------------------------------------
134--------------------------------------------------------------------------------
libs/base/Data/Matrix.idr → libs/contrib/Data/Matrix.idrrenamed+2−8
@@ -1,5 +1,7 @@
1module Data.Matrix
1module Data.Matrix
2
2
3+import Control.Algebra
4+
3import Data.Complex
5import Data.Complex
4import Data.ZZ
6import Data.ZZ
5import Data.Fin
7import Data.Fin
@@ -212,14 +214,6 @@ instance Semigroup Nat where
212instance Monoid Nat where
214instance Monoid Nat where
213 neutral = 0
215 neutral = 0
214
216
215−instance VerifiedSemigroup Nat where
216− semigroupOpIsAssociative = plusAssociative
217−
218−instance VerifiedMonoid Nat where
219− monoidNeutralIsNeutralL = plusZeroRightNeutral
220− monoidNeutralIsNeutralR = plusZeroLeftNeutral
221−
222−
223instance Semigroup ZZ where
217instance Semigroup ZZ where
224 (<+>) = (+)
218 (<+>) = (+)
225
219
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
181 primitiveEq = believe_me (Refl {x})
181 primitiveEq = believe_me (Refl {x})
182 postulate primitiveNotEq : x = y -> Void
182 postulate primitiveNotEq : x = y -> Void
183
183
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
193
184
194--------------------------------------------------------------------------------
185--------------------------------------------------------------------------------
195-- String
186-- String
libs/prelude/Prelude.idr+1−1
@@ -23,7 +23,7 @@ import public Prelude.Bits
23import public Prelude.Uninhabited
23import public Prelude.Uninhabited
24import public Prelude.Pairs
24import public Prelude.Pairs
25import public Prelude.Stream
25import public Prelude.Stream
26−
26+import public Prelude.Providers
27import public Decidable.Equality
27import public Decidable.Equality
28import public Language.Reflection
28import public Language.Reflection
29import public Language.Reflection.Errors
29import public Language.Reflection.Errors
libs/prelude/Prelude/Algebra.idr−294
@@ -22,8 +22,6 @@ infixl 5 <#>
22class Semigroup a where
22class Semigroup a where
23 (<+>) : a -> a -> a
23 (<+>) : a -> a -> a
24
24
25−class Semigroup a => VerifiedSemigroup a where
26− total semigroupOpIsAssociative : (l, c, r : a) -> l <+> (c <+> r) = (l <+> c) <+> r
27
25
28||| Sets equipped with a single binary operation that is associative, along with
26||| Sets equipped with a single binary operation that is associative, along with
29||| a neutral element for that binary operation. Must satisfy the following
27||| a neutral element for that binary operation. Must satisfy the following
@@ -37,295 +35,3 @@ class Semigroup a => VerifiedSemigroup a where
37class Semigroup a => Monoid a where
35class Semigroup a => Monoid a where
38 neutral : a
36 neutral : a
39
37
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
15 pure : a -> f a
15 pure : a -> f a
16 (<*>) : f (a -> b) -> f a -> f b
16 (<*>) : f (a -> b) -> f a -> f b
17
17
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−
29infixl 2 <*
18infixl 2 <*
30(<*) : Applicative f => f a -> f b -> f a
19(<*) : Applicative f => f a -> f b -> f a
31a <* b = map const a <*> b
20a <* b = map const a <*> b
libs/prelude/Prelude/Functor.idr−6
@@ -18,9 +18,3 @@ infixl 4 <$>
18(<$>) : Functor f => (m : a -> b) -> f a -> f b
18(<$>) : Functor f => (m : a -> b) -> f a -> f b
19m <$> x = map m x
19m <$> x = map m x
20
20
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) =
809hasAnyNilFalse : Eq a => (l : List a) -> hasAny [] l = False
809hasAnyNilFalse : Eq a => (l : List a) -> hasAny [] l = False
810hasAnyNilFalse l = ?hasAnyNilFalseBody
810hasAnyNilFalse l = ?hasAnyNilFalseBody
811
811
812−instance VerifiedSemigroup (List a) where
813− semigroupOpIsAssociative = appendAssociative
814−
815−instance VerifiedMonoid (List a) where
816− monoidNeutralIsNeutralL = appendNilRightNeutral
817− monoidNeutralIsNeutralR xs = Refl
818
812
819--------------------------------------------------------------------------------
813--------------------------------------------------------------------------------
820-- Proofs
814-- Proofs
libs/prelude/Prelude/Monad.idr−10
@@ -14,16 +14,6 @@ infixl 5 >>=
14class Applicative m => Monad (m : Type -> Type) where
14class Applicative m => Monad (m : Type -> Type) where
15 (>>=) : m a -> (a -> m b) -> m b
15 (>>=) : m a -> (a -> m b) -> m b
16
16
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−
27||| Also called `join` or mu
17||| Also called `join` or mu
28flatten : Monad m => m (m a) -> m a
18flatten : Monad m => m (m a) -> m a
29flatten a = a >>= id
19flatten a = a >>= id
libs/prelude/Prelude/Nat.idr−12
@@ -239,18 +239,6 @@ instance Monoid Multiplicative where
239instance Monoid Additive where
239instance Monoid Additive where
240 neutral = getAdditive Z
240 neutral = getAdditive Z
241
241
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−
254||| Casts negative `Ints` to 0.
242||| Casts negative `Ints` to 0.
255instance Cast Int Nat where
243instance Cast Int Nat where
256 cast i = fromInteger (cast i)
244 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
2
6
3||| Type providers must build one of these in an IO computation.
7||| Type providers must build one of these in an IO computation.
4public
8public
libs/prelude/prelude.ipkg+1−1
@@ -8,7 +8,7 @@ modules = Builtins, Prelude, IO,
8 Prelude.Maybe, Prelude.Monad, Prelude.Applicative, Prelude.Either,
8 Prelude.Maybe, Prelude.Monad, Prelude.Applicative, Prelude.Either,
9 Prelude.Strings, Prelude.Chars, Prelude.Functor,
9 Prelude.Strings, Prelude.Chars, Prelude.Functor,
10 Prelude.Foldable, Prelude.Traversable, Prelude.Bits, Prelude.Stream,
10 Prelude.Foldable, Prelude.Traversable, Prelude.Bits, Prelude.Stream,
11− Prelude.Uninhabited, Prelude.Pairs,
11+ Prelude.Uninhabited, Prelude.Pairs, Prelude.Providers,
12
12
13 Language.Reflection, Language.Reflection.Errors, Language.Reflection.Tactical,
13 Language.Reflection, Language.Reflection.Errors, Language.Reflection.Tactical,
14
14
src/Idris/Elab/Provider.hs+1−1
@@ -112,7 +112,7 @@ elabProvider doc info syn fc what n
112 -- error messages with less normalisation
112 -- error messages with less normalisation
113 providerOf :: Type -> Type
113 providerOf :: Type -> Type
114 providerOf ty = App (P Ref (sUN "IO") Erased) $
114 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)
116 ty
116 ty
117
117
118 isProviderOf :: Context -> TT Name -> TT Name -> Bool
118 isProviderOf :: Context -> TT Name -> TT Name -> Bool
src/Idris/Providers.hs+3−3
@@ -10,16 +10,16 @@ import Idris.Error
10-- | Wrap a type provider in the type of type providers
10-- | Wrap a type provider in the type of type providers
11providerTy :: FC -> PTerm -> PTerm
11providerTy :: FC -> PTerm -> PTerm
12providerTy fc tm
12providerTy 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]
14
14
15ioret :: Name
15ioret :: Name
16ioret = sUN "prim_io_return"
16ioret = sUN "prim_io_return"
17
17
18ermod :: Name
18ermod :: Name
19−ermod = sNS (sUN "Error") ["Providers"]
19+ermod = sNS (sUN "Error") ["Providers", "Prelude"]
20
20
21prmod :: Name
21prmod :: Name
22−prmod = sNS (sUN "Provide") ["Providers"]
22+prmod = sNS (sUN "Provide") ["Providers", "Prelude"]
23
23
24data Provided a = Provide a
24data Provided a = Provide a
25 deriving (Show, Eq, Functor)
25 deriving (Show, Eq, Functor)
test/basic011/run+1−1
@@ -1,4 +1,4 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2−idris $@ basic011.idr -o basic011
2+idris $@ basic011.idr -p contrib -o basic011
3./basic011
3./basic011
4rm -f basic011 *.ibc
4rm -f basic011 *.ibc
test/docs002/docs002.idr−3
@@ -1,9 +1,6 @@
1module Main
1module Main
2
2
3-- Simple test case for type provider documentation.
3-- Simple test case for type provider documentation.
4−
5−import Providers
6−
7%language TypeProviders
4%language TypeProviders
8
5
9getType : Int -> IO (Provider Type)
6getType : 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
2
2
3-- Simple test case for trivial type providers.
3-- Simple test case for trivial type providers.
4
4
5−import Providers
6−
7%language TypeProviders
5%language TypeProviders
8
6
9-- Provide the Unit type
7-- Provide the Unit type
test/ffi004/test026.idr−2
@@ -2,8 +2,6 @@ module Main
2
2
3-- Simple test case for trivial type providers.
3-- Simple test case for trivial type providers.
4
4
5−import Providers
6−
7%language TypeProviders
5%language TypeProviders
8
6
9strToType : String -> Type
7strToType : String -> Type
test/ffi005/Postulate.idr−2
@@ -1,7 +1,5 @@
1module Main
1module Main
2
2
3−import Providers
4−
5%language TypeProviders
3%language TypeProviders
6
4
7bad : IO (Provider Type)
5bad : IO (Provider Type)
test/interactive007/run+1−1
@@ -1,2 +1,2 @@
1#!/usr/bin/env bash
1#!/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 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2−idris $@ test018.idr -o test018
2+idris $@ test018.idr -p contrib -o test018
3−idris $@ test018a.idr -o test018a
3+idris $@ test018a.idr -p contrib -o test018a
4./test018
4./test018
5#./test018a
5#./test018a
6rm -f test018 test018a *.ibc
6rm -f test018 test018a *.ibc
test/primitives003/expected−2
@@ -16,8 +16,6 @@ True
16False
16False
17True
17True
18False
18False
19−True
20−False
21False
19False
22True
20True
23False
21False
test/primitives003/test038.idr−3
@@ -40,9 +40,6 @@ main = do
40 -- Booleans
40 -- Booleans
41 putStrLn . show $ test True True
41 putStrLn . show $ test True True
42 putStrLn . show $ test True False
42 putStrLn . show $ test True False
43− -- Float
44− putStrLn . show $ test 1.0 1.0
45− putStrLn . show $ test 1.0 2.0
46 -- Maybe
43 -- Maybe
47 putStrLn . show $ test (Just "hello") (Just "hello")
44 putStrLn . show $ test (Just "hello") (Just "hello")
48 putStrLn . show $ test (Just "hello") (Just "world")
45 putStrLn . show $ test (Just "hello") (Just "world")
test/reg048/run+1−1
@@ -1,4 +1,4 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2−idris $@ reg048.idr -o reg048
2+idris $@ reg048.idr -p contrib -o reg048
3./reg048
3./reg048
4rm -f reg048 *.ibc
4rm -f reg048 *.ibc