From 811f0903d9b177a93ad9194e7e4370119f61d413 Mon Sep 17 00:00:00 2001 From: Armando Blancas Date: Mon, 15 Apr 2013 14:44:55 -0700 Subject: [PATCH 01/11] Bumped up version to dot three. --- pom.xml | 4 ++-- project.clj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 88ab8e8..38218cd 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.blancas morph jar - 0.2.0 + 0.3.0 Morph A Library of Morphisms: Monoids, Functors, and Monads @@ -65,7 +65,7 @@ criterium criterium - 0.2.1 + 0.3.1 org.clojure diff --git a/project.clj b/project.clj index 6f40034..6ef6fca 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.blancas/morph "0.2.0" +(defproject org.blancas/morph "0.3.0" :description "A Library of Morphisms: Monoids, Functors, and Monads" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} From 0e7f03600d964043b5aa412431b12f9d8b9ea0e1 Mon Sep 17 00:00:00 2001 From: Armando Blancas Date: Mon, 15 Apr 2013 14:45:36 -0700 Subject: [PATCH 02/11] Added type hints to core, monads, transf. --- src/main/clojure/blancas/morph/core.clj | 45 ++++++++++++----------- src/main/clojure/blancas/morph/monads.clj | 26 ++++++------- src/main/clojure/blancas/morph/transf.clj | 32 ++++++++-------- 3 files changed, 52 insertions(+), 51 deletions(-) diff --git a/src/main/clojure/blancas/morph/core.clj b/src/main/clojure/blancas/morph/core.clj index 9063889..b5e0fc8 100644 --- a/src/main/clojure/blancas/morph/core.clj +++ b/src/main/clojure/blancas/morph/core.clj @@ -138,16 +138,16 @@ (deftype Sum [sum] Object - (equals [this x] (= sum (.sum x))) + (equals [this x] (= sum (.sum ^Sum x))) Comparable - (compareTo [this x] (compare sum (.sum x))) + (compareTo [this x] (compare sum (.sum ^Sum x))) Monoid (mempty [this] sum-id) - (mappend [this x] (Sum. (+ sum (.sum x))))) + (mappend [this x] (Sum. (+ sum (.sum ^Sum x))))) (defn sum "Accessor for a Sum type." - [s] (.sum s)) + [^Sum s] (.sum s)) (defmethod print-method Sum [r, ^java.io.Writer w] (.write w "Sum ") @@ -163,16 +163,16 @@ (deftype Product [product] Object - (equals [this x] (= product (.product x))) + (equals [this x] (= product (.product ^Product x))) Comparable - (compareTo [this x] (compare product (.product x))) + (compareTo [this x] (compare product (.product ^Product x))) Monoid (mempty [this] prod-id) - (mappend [this x] (Product. (* product (.product x))))) + (mappend [this x] (Product. (* product (.product ^Product x))))) (defn product "Accessor for a Product type." - [s] (.product s)) + [^Product s] (.product s)) (defmethod print-method Product [r, ^java.io.Writer w] (.write w "Product ") @@ -188,16 +188,16 @@ (deftype Any [any] Object - (equals [this x] (= any (.any x))) + (equals [this x] (= any (.any ^ Any x))) Comparable - (compareTo [this x] (compare any (.any x))) + (compareTo [this x] (compare any (.any ^Any x))) Monoid (mempty [this] any-id) - (mappend [this x] (Any. (or any (.any x))))) + (mappend [this x] (Any. (or any (.any ^Any x))))) (defn any "Accessor for the Any type." - [s] (.any s)) + [^Any s] (.any s)) (defmethod print-method Any [r, ^java.io.Writer w] (.write w "Any ") @@ -213,16 +213,16 @@ (deftype All [all] Object - (equals [this x] (= all (.all x))) + (equals [this x] (= all (.all ^All x))) Comparable - (compareTo [this x] (compare all (.all x))) + (compareTo [this x] (compare all (.all ^All x))) Monoid (mempty [this] all-id) - (mappend [this x] (All. (and all (.all x))))) + (mappend [this x] (All. (and all (.all ^All x))))) (defn all "Accessor for the All type." - [s] (.all s)) + [^All s] (.all s)) (defmethod print-method All [r, ^java.io.Writer w] (.write w "All ") @@ -239,24 +239,25 @@ (deftype Pair [fst snd] Object (equals [this x] - (and (= fst (.fst x)) (= snd (.snd x)))) + (and (= fst (.fst ^Pair x)) (= snd (.snd ^Pair x)))) Comparable (compareTo [this x] - (let [result (compare fst (.fst x))] + (let [result (compare fst (.fst ^Pair x))] (if (zero? result) - (compare snd (.snd x)) + (compare snd (.snd ^Pair x)) result))) Monoid (mempty [this] (Pair. (mempty fst) (mempty snd))) - (mappend [this x] (Pair. (mappend fst (.fst x)) (mappend snd (.snd x))))) + (mappend [this x] (Pair. (mappend fst (.fst ^Pair x)) + (mappend snd (.snd ^Pair x))))) (defn fst "Accessor for the first element of a pair." - [p] (.fst p)) + [^Pair p] (.fst p)) (defn snd "Accessor for the second element of a pair." - [p] (.snd p)) + [^Pair p] (.snd p)) (defmethod print-method Pair [r, ^java.io.Writer w] (.write w "Pair(") diff --git a/src/main/clojure/blancas/morph/monads.clj b/src/main/clojure/blancas/morph/monads.clj index 738a52c..fc8d968 100644 --- a/src/main/clojure/blancas/morph/monads.clj +++ b/src/main/clojure/blancas/morph/monads.clj @@ -22,7 +22,7 @@ (defn run-id "Returns the value held by an Identity type." - [m] (.value m)) + [^Identity m] (.value m)) (defmethod print-method Identity [r, ^java.io.Writer w] @@ -58,7 +58,7 @@ (deftype Maybe [value] Object (equals [this other] - (= value (.value other))) + (= value (.value ^Maybe other))) (hashCode [this] (if value (.hashCode value) 0)) (toString [this] @@ -91,17 +91,17 @@ (defn run-just "Returns the boxed value of m." - [m] (.value m)) + [^Maybe m] (.value m)) (defn just? "Checks for a maybe with a value." - [m] (not (nil? (.value m)))) + [^Maybe m] (not (nil? (.value m)))) (defn nothing? "Checks for a maybe with nothing." - [m] (nil? (.value m))) + [^Maybe m] (nil? (.value m))) (defmacro may @@ -198,12 +198,12 @@ (defn run-left "Accessor for the Left value." - [m] (.left m)) + [^Either m] (.left m)) (defn run-right "Accessor for the Right value." - [m] (.right m)) + [^Either m] (.right m)) (defn left? @@ -282,7 +282,7 @@ (defn run-reader "Performs a Reader action m with an environment e. Returns the value produced by the action." - [m e] ((.f m) e)) + [^Reader m e] ((.f m) e)) (defmethod print-method Reader [r, ^java.io.Writer w] @@ -340,19 +340,19 @@ (defn eval-writer "Returns the value of a writer." - [m] (.value m)) + [^Writer m] (.value m)) (defn exec-writer "Returns the output of a writer." - [m] (.output m)) + [^Writer m] (.output m)) (defmethod print-method Writer [r, ^java.io.Writer w] (.write w "Writer(") - (print (.value r)) + (print (.value ^Writer r)) (.write w ",") - (print (.output r)) + (print (.output ^Writer r)) (.write w ")")) @@ -418,7 +418,7 @@ (defn run-state "Performs an action m with an initial state s. Returns a pair with the value and the state." - [m s] ((.f m) s)) + [^State m s] ((.f m) s)) (defn eval-state diff --git a/src/main/clojure/blancas/morph/transf.clj b/src/main/clojure/blancas/morph/transf.clj index c51e0a9..0d22d8c 100644 --- a/src/main/clojure/blancas/morph/transf.clj +++ b/src/main/clojure/blancas/morph/transf.clj @@ -39,13 +39,13 @@ (defn run-just-t "Returns the inner monad, which contains a Maybe value." - [m] (.im m)) + [^MaybeT m] (.im m)) (defn eval-just-t "Returns the Just value inside the inner monad in a new instance; thus, from m (Just a) it returns m a." - [m] + [^MaybeT m] (monad [may (run-just-t m)] ((.ret m) (run-just may)))) @@ -90,7 +90,7 @@ (defn run-either-t "Returns the inner monad, which contains an Either value." - [m] (.im m)) + [^EitherT m] (.im m)) (defn left-t @@ -106,7 +106,7 @@ (defn run-left-t "Accessor for the left value as an instance of the inner monad; in effect: m (Either e a) -> m e" - [m] + [^EitherT m] (monad [x (run-either-t m)] ((.ret m) (run-left x)))) @@ -114,7 +114,7 @@ (defn run-right-t "Accessor for the right value as an instance of the inner monad; in effect: m (Either e a) -> m a" - [m] + [^EitherT m] (monad [x (run-either-t m)] ((.ret m) (run-right x)))) @@ -165,7 +165,7 @@ (defn run-reader-t "Performs a Reader action m with an environment e. Returns the inner monad produced by the action." - [m e] ((.run m) e)) + [^ReaderT m e] ((.run m) e)) (defmethod print-method ReaderT [r, ^java.io.Writer w] @@ -236,19 +236,19 @@ (defn run-writer-t "Returns the inner monad." - [m] (.im m)) + [^WriterT m] (.im m)) (defn eval-writer-t "Returns the value part as an instance of the inner monad: m (a)." - [m] + [^WriterT m] (monad [p (run-writer-t m)] ((.ret m) (fst p)))) (defn exec-writer-t "Returns the output part as an instance of the inner monad: m (w)." - [m] + [^WriterT m] (monad [p (run-writer-t m)] ((.ret m) (snd p)))) @@ -265,7 +265,7 @@ takes a WriterT and an inner monad value." ([ret a w] (->WriterT ret (mempty w) (ret (->Pair a w)))) - ([m im] + ([^WriterT m im] (->WriterT (.ret m) (.me m) im))) @@ -298,7 +298,7 @@ (defn listen-wt "Allows chained WriterT's to peek at the current output w by returning a value as a pair (a, w)." - [m] + [^WriterT m] (writer-t m (monad [p (run-writer-t m)] ((.ret m) (->Pair p (snd p)))))) @@ -306,7 +306,7 @@ (defn listens-wt "Allows chained WriterT's to peek at the current output w by returning a value as a pair (a, f w)." - [f m] + [f ^WriterT m] (writer-t m (monad [p (run-writer-t m)] (let [a (fst p) w (snd p)] ((.ret m) (->Pair (->Pair a (f w)) w)))))) @@ -317,7 +317,7 @@ but instead of output it adds an output-transforming function to the value's pair. Returns a WriterT whose output is the result of that function." - [m] + [^WriterT m] (writer-t m (monad [p (run-writer-t m)] (let [a (fst (fst p)) f (snd (fst p)) w (snd p)] ((.ret m) (->Pair a (f w))))))) @@ -352,13 +352,13 @@ (defn run-state-t "Performs an action m using the initial state s; returns the wrapped monad having a pair of the value and state." - [m s] ((.run m) s)) + [^StateT m s] ((.run m) s)) (defn eval-state-t "Performs an action m using the initial state s; returns the wrapped monad with the resulting value." - [m s] + [^StateT m s] (monad [p (run-state-t m s)] ((.ret m) (fst p)))) @@ -366,7 +366,7 @@ (defn exec-state-t "Performs an action m using the initial state s; returns the wrapped monad with the resulting state." - [m s] + [^StateT m s] (monad [p (run-state-t m s)] ((.ret m) (snd p)))) From 85ed56e1e5dea13e358591f120cc49af05a2ab55 Mon Sep 17 00:00:00 2001 From: Armando Blancas Date: Mon, 15 Apr 2013 21:32:04 -0700 Subject: [PATCH 03/11] Updates for rel dot three. --- README.md | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 91a0517..f27f7dc 100644 --- a/README.md +++ b/README.md @@ -14,23 +14,15 @@ and that encapsulate the boilerplate employed by many programming techniques. * Library of generic functions for the above constructs. * Sample code in `src/main/resources`. -## Setup - -Leiningen: - -```clojure -[org.blancas/morph "0.2.0"] -``` - -Maven: +These constructs have a reputation of being hard to explain and even harder to +understand and to apply in everyday programming. I've made every effort to +present them as regular techniques and idioms with practical benefits. Behind +their strange or fancy names, these are just functions that work on data types. -```xml - - org.blancas - morph - 0.2.0 - -``` +An intuition of their behavior is all that's needed to take advantage of these +functions; you may never need or want to write your own. I'm pleased with the +power and simplicity these techniques have to offer and I hope you may find +them useful as well. ## Sample Usage @@ -85,13 +77,35 @@ Now we evaluate some expressions with `table` as the initial state. ;; {j 5, k 30} ``` +## Setup + +Leiningen: + +```clojure +[org.blancas/morph "0.3.0"] +``` + +Maven: + +```xml + + org.blancas + morph + 0.3.0 + +``` + +### Changes for release 0.3.0: + +* Fixed slow, reflective calls by adding type hints. + ## Documentation Browse the [change log](https://github.com/blancas/morph/wiki/Change-Log). Morph is documented in the [Wiki](https://github.com/blancas/morph/wiki). -Browse the Codox [Morph v0.2.0 API](http://blancas.github.com/morph). +Browse the Codox [Morph v0.3.0 API](http://blancas.github.com/morph). To generate the API docs (in the `codox` directory): From 52823cadbb848de0c20b982a60342124b24b16ff Mon Sep 17 00:00:00 2001 From: Armando Blancas Date: Mon, 15 Apr 2013 21:33:52 -0700 Subject: [PATCH 04/11] Updates for rel dot three. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f27f7dc..e2b24ba 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ Maven: ## Documentation -Browse the [change log](https://github.com/blancas/morph/wiki/Change-Log). +Browse the whole [change log](https://github.com/blancas/morph/wiki/Change-Log). Morph is documented in the [Wiki](https://github.com/blancas/morph/wiki). From 26e9ee7e509449039be909f2f81cd4de0294200f Mon Sep 17 00:00:00 2001 From: Armando Blancas Date: Mon, 10 Jun 2013 21:06:40 -0700 Subject: [PATCH 05/11] Added tests for monoids. --- src/test/clojure/blancas/morph/test_core.clj | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/clojure/blancas/morph/test_core.clj b/src/test/clojure/blancas/morph/test_core.clj index ab82a67..fa1375b 100644 --- a/src/test/clojure/blancas/morph/test_core.clj +++ b/src/test/clojure/blancas/morph/test_core.clj @@ -277,11 +277,22 @@ (fmap square [3 7 11 13 20]) => '(9 49 121 169 400))) +(deftest test-0110-05 + (fact "a vector is a functor that produces a vector" + (fmap square [3 7 11 13 20]) => vector?)) + + (deftest test-0115 (fact "a subvector is a functor" (fmap square (subvec [1 2 3 7 11 13 20] 2)) => '(9 49 121 169 400))) +(deftest test-0115-05 + (fact "a subvector is a functor that produces a subvector" + (instance? clojure.lang.PersistentVector + (fmap square (subvec [1 2 3 7 11 13 20] 2))) => true)) + + (deftest test-0120 (let [s (fmap square #{3 7 11 13 20})] (fact "a hash set is a functor" @@ -293,6 +304,12 @@ (s 400) => 400))) +(deftest test-0120-05 + (let [s (fmap square #{3 7 11 13 20})] + (fact "a hash set is a functor that produces a set" + s => set?))) + + (deftest test-0125 (let [s (fmap square (sorted-set 8 3 7 12 6 4))] (fact "a sorted set is a functor" @@ -320,6 +337,13 @@ (fmap square (sorted-map :one 20 :two 30)) => {:one 400 :two 900})) +(deftest test-0140-05 + (fact "a map functor produces a map" + (fmap square (array-map :one 20 :two 30)) => map? + (fmap square (hash-map :one 20 :two 30)) => map? + (fmap square (sorted-map :one 20 :two 30)) => map?)) + + (deftest test-0145 (let [e (clojure.lang.PersistentQueue/EMPTY) q (-> e (conj 2) (conj 4) (conj 8) (conj 12))] @@ -346,6 +370,12 @@ (fmap square lst) => '(9 49 121 169 400)))) +(deftest test-0160-05 + (let [lst (map identity '(3 7 11 13 20))] + (fact "a lazy-seq is a functor that produces a lazy seq" + (fmap square lst) => seq?))) + + (deftest test-0165 (let [p1 (->Pair 9 12)] (fact "a pair is a functor" From 1a2fc6c59ad3765c919fed35e5c3807a03753b2f Mon Sep 17 00:00:00 2001 From: Armando Blancas Date: Tue, 11 Jun 2013 22:14:32 -0700 Subject: [PATCH 06/11] Added deflazytype. --- src/main/clojure/blancas/morph/core.clj | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/clojure/blancas/morph/core.clj b/src/main/clojure/blancas/morph/core.clj index b5e0fc8..4734339 100644 --- a/src/main/clojure/blancas/morph/core.clj +++ b/src/main/clojure/blancas/morph/core.clj @@ -106,6 +106,39 @@ (apply f y x more))) +;; +-------------------------------------------------------------+ +;; | Lazy Evaluation. | +;; +-------------------------------------------------------------+ + + +(defmacro deflazytype + "Like deftype but fields are evaluated lazily. + + This macro creates a deftype definition and a constructor macro + that will delay its arguments. The type implements IKeywordLookup + so that fields may work as accessors like in defrecord. These + accessors will first force the field's value. Example: + + (deflazytype MyRec [foo bar]) ;; defines MyRec, implements IKeywordLookup + (def rec (MyRec* form1 form2)) ;; returns immediately, won't eval forms + (:foo rec) ;; (force)'ed value of form1 + (:bar rec) ;; (force)'ed value of form2" + [name fields] + (let [clauses (interleave (map (comp keyword str) fields) + (for [f fields] (list 'clojure.core/force f))) + delays (for [f fields] (list 'list (list 'quote 'clojure.core/delay) f)) + ctorfun (symbol (str name "*")) + ctorsym (symbol (str name ".")) + typdecl `(deftype ~name ~fields + clojure.lang.IKeywordLookup + (getLookupThunk [t1# k#] + (reify clojure.lang.ILookupThunk + (get [t2# tgt#] (case k# ~@clauses nil))))) + macdecl (list 'defmacro ctorfun fields + (concat (list 'list (list 'quote ctorsym)) delays))] + (list 'do typdecl macdecl))) + + ;; +-------------------------------------------------------------+ ;; | Monoids. | ;; +-------------------------------------------------------------+ From e7dd57d9cea9e21233209db168522459f1b7d867 Mon Sep 17 00:00:00 2001 From: Armando Blancas Date: Wed, 12 Jun 2013 20:58:12 -0700 Subject: [PATCH 07/11] Replaced deflazytype with simpler implementation. --- src/main/clojure/blancas/morph/core.clj | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/clojure/blancas/morph/core.clj b/src/main/clojure/blancas/morph/core.clj index 4734339..b9ffe71 100644 --- a/src/main/clojure/blancas/morph/core.clj +++ b/src/main/clojure/blancas/morph/core.clj @@ -124,19 +124,17 @@ (:foo rec) ;; (force)'ed value of form1 (:bar rec) ;; (force)'ed value of form2" [name fields] - (let [clauses (interleave (map (comp keyword str) fields) - (for [f fields] (list 'clojure.core/force f))) - delays (for [f fields] (list 'list (list 'quote 'clojure.core/delay) f)) + (let [clauses (interleave (map keyword fields) (for [f fields] `(force ~f))) ctorfun (symbol (str name "*")) - ctorsym (symbol (str name ".")) - typdecl `(deftype ~name ~fields - clojure.lang.IKeywordLookup - (getLookupThunk [t1# k#] - (reify clojure.lang.ILookupThunk - (get [t2# tgt#] (case k# ~@clauses nil))))) - macdecl (list 'defmacro ctorfun fields - (concat (list 'list (list 'quote ctorsym)) delays))] - (list 'do typdecl macdecl))) + delays (for [f fields] `(list 'delay ~f)) + ctorsym `(quote ~(symbol (str name ".")))] + `(do + (deftype ~name ~fields + clojure.lang.IKeywordLookup + (getLookupThunk [t1# k#] + (reify clojure.lang.ILookupThunk + (get [t2# tgt#] (case k# ~@clauses nil))))) + (defmacro ~ctorfun ~fields `(~~ctorsym ~~@delays))))) ;; +-------------------------------------------------------------+ From 8f80fc756719acc00b4dc20191fb19ecb939cb78 Mon Sep 17 00:00:00 2001 From: Armando Blancas Date: Wed, 12 Jun 2013 21:34:27 -0700 Subject: [PATCH 08/11] Added test case for deflazytype. --- src/test/clojure/blancas/morph/test_core.clj | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/clojure/blancas/morph/test_core.clj b/src/test/clojure/blancas/morph/test_core.clj index fa1375b..352d4cb 100644 --- a/src/test/clojure/blancas/morph/test_core.clj +++ b/src/test/clojure/blancas/morph/test_core.clj @@ -518,3 +518,17 @@ (fact "defcurry defines a one-arg function" (f1 7) => 49 (map f1 (range 5)) => [0 1 4 9 16])) + + +;; +-------------------------------------------------------------+ +;; | Lazy Evaluation. | +;; +-------------------------------------------------------------+ + + +(deflazytype MyType [foo bar]) + +(deftest test-0700 + (let [inst (MyType* 5005 "rifa")] + (fact "deflazytype defines a type that delays its fields" + (:foo inst) => 5005 + (:bar inst) => "rifa"))) From ceb5772e23e8e8c6d42abeca88d681b59be87f20 Mon Sep 17 00:00:00 2001 From: Armando Blancas Date: Wed, 30 Apr 2014 12:07:05 -0700 Subject: [PATCH 09/11] Added ack for YourKit --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index e2b24ba..565d0a0 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,17 @@ To generate the API docs (in the `codox` directory): lein doc +## YourKit + +YourKit is kindly supporting open source projects with its full-featured Java +Profiler. + +YourKit, LLC is the creator of innovative and intelligent tools for profiling +Java and .NET applications. Take a look at YourKit's leading software products: + +* YourKit Java Profiler and +* YourKit .NET Profiler. + ## License Copyright © 2013 Armando Blancas. From 9cde699dc65654fb6be70b810e8dcf216633fb19 Mon Sep 17 00:00:00 2001 From: Armando Blancas Date: Wed, 30 Apr 2014 12:07:34 -0700 Subject: [PATCH 10/11] Bumped version to 0.5.0; updated dependencies --- pom.xml | 16 ++++++++-------- project.clj | 15 +++++++++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 38218cd..49d612e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.blancas morph jar - 0.3.0 + 0.5.0 Morph A Library of Morphisms: Monoids, Functors, and Monads @@ -49,33 +49,33 @@ org.clojure clojure - 1.5.1 + 1.6.0 jline jline - 0.9.94 + 1.0 midje midje - 1.5.0 + 1.6.3 test criterium criterium - 0.3.1 + 0.4.3 org.clojure tools.macro - 0.1.1 + 0.1.2 org.clojure tools.trace - 0.7.5 + 0.7.8 autodoc @@ -111,7 +111,7 @@ com.theoryinpractise clojure-maven-plugin - 1.3.13 + 1.3.20 true -Dfile.encoding=UTF-8 diff --git a/project.clj b/project.clj index 6ef6fca..9e193f3 100644 --- a/project.clj +++ b/project.clj @@ -1,9 +1,9 @@ -(defproject org.blancas/morph "0.3.0" +(defproject org.blancas/morph "0.5.0" :description "A Library of Morphisms: Monoids, Functors, and Monads" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :url "https://github.com/blancas/morph" - :dependencies [[org.clojure/clojure "1.5.1"]] + :dependencies [[org.clojure/clojure "1.6.0"]] :source-paths ["src/main/clojure"] :test-paths ["src/test/clojure"] :jvm-opts ["-Dfile.encoding=UTF-8"] @@ -11,7 +11,14 @@ {:1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]} :1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]} :1.5 {:dependencies [[org.clojure/clojure "1.5.0"]]} + :1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]} :dev {:resource-paths ["src/main/resources" "src/test/resources"] - :dependencies [[midje "1.5.0" :exclusions [org.clojure/clojure]]] - :plugins [[codox "0.6.4"]] + :dependencies [[org.clojure/clojure "1.6.0"] + [org.clojure/tools.macro "0.1.2"] + [org.clojure/tools.trace "0.7.8"] + [org.clojure/tools.nrepl "0.2.3"] + [midje "1.6.3" :exclusions [org.clojure/clojure]] + [criterium "0.4.3"] + [jline "1.0"]] + :plugins [[codox "0.6.8"]] :codox {:sources ["src/main/clojure"] :output-dir "codox"}}}) From 01c956ddb65ca2bf105029a2767418735bbfde87 Mon Sep 17 00:00:00 2001 From: Armando Blancas Date: Tue, 11 Aug 2015 21:35:06 -0700 Subject: [PATCH 11/11] Fixes #9 Added Object overrides to Identity, Either --- project.clj | 5 +++-- src/main/clojure/blancas/morph/monads.clj | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/project.clj b/project.clj index 9e193f3..47a0bf8 100644 --- a/project.clj +++ b/project.clj @@ -3,7 +3,7 @@ :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :url "https://github.com/blancas/morph" - :dependencies [[org.clojure/clojure "1.6.0"]] + :dependencies [[org.clojure/clojure "1.7.0"]] :source-paths ["src/main/clojure"] :test-paths ["src/test/clojure"] :jvm-opts ["-Dfile.encoding=UTF-8"] @@ -12,8 +12,9 @@ :1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]} :1.5 {:dependencies [[org.clojure/clojure "1.5.0"]]} :1.6 {:dependencies [[org.clojure/clojure "1.6.0"]]} + :1.7 {:dependencies [[org.clojure/clojure "1.7.0"]]} :dev {:resource-paths ["src/main/resources" "src/test/resources"] - :dependencies [[org.clojure/clojure "1.6.0"] + :dependencies [[org.clojure/clojure "1.7.0"] [org.clojure/tools.macro "0.1.2"] [org.clojure/tools.trace "0.7.8"] [org.clojure/tools.nrepl "0.2.3"] diff --git a/src/main/clojure/blancas/morph/monads.clj b/src/main/clojure/blancas/morph/monads.clj index fc8d968..ed26ad3 100644 --- a/src/main/clojure/blancas/morph/monads.clj +++ b/src/main/clojure/blancas/morph/monads.clj @@ -17,7 +17,14 @@ ;; +-------------------------------------------------------------+ -(deftype Identity [value]) +(deftype Identity [value] + Object + (equals [this other] + (= value (.value ^Identity other))) + (hashCode [this] + (if value (.hashCode value) 0)) + (toString [this] + (with-out-str (print this)))) (defn run-id @@ -160,7 +167,15 @@ ;; +-------------------------------------------------------------+ -(deftype Either [left right]) +(deftype Either [left right] + Object + (equals [this other] + (and (= left (.left ^Either other)) + (= right (.right ^Either other)))) + (hashCode [this] + (if (or left right) (.hashCode [left right]) 0)) + (toString [this] + (with-out-str (print this)))) (defn left