Created
October 10, 2012 16:47
-
-
Save frenchy64/3866807 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def-alias Monad | |
(TFn [[m :kind (TFn [[x :variance :covariant]] Any)]] | |
'{:m-bind (All [x y] | |
[(m x) [x -> (m y)] -> (m y)]) | |
:m-result (All [x] | |
[x -> (m x)]) | |
:m-zero Undefined | |
:m-plus Undefined})) | |
(ann maybe-m (Monad | |
(TFn [[x :variance :covariant]] | |
(U nil x)))) | |
(defn maybe-m ...) | |
(ann maybe-t | |
(All [[m :kind (TFn [[x :variance :covariant]] Any)]] | |
[(Monad m) nil (U ':m-plus-default ':m-plus-from-base) | |
-> (Monad (TFn [[y :variance :covariant]] | |
(m (U nil y))))])) | |
(defn maybe-t ...) | |
(ann seq-maybe-m (Monad | |
(TFn [[x :variance :covariant]] | |
(Seqable (U nil x))))) | |
(def seq-maybe-m ((inst maybe-t | |
(TFn [[x :variance :covariant]] | |
(Seqable x))) | |
sequence-m nil :m-plus-default)) | |
(domonad seq-maybe-m | |
[^{:T AnyInteger} x (map (fn> [[n :- AnyInteger]] (when (odd? n) n)) (range 10))] | |
(inc x)) | |
;=> (clojure.lang.Seqable (U nil AnyInteger)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment