Discussion:
Protocols in cljs
Pedro Viegas
2014-09-22 20:26:34 UTC
Permalink
Hi! I am trying to annotate a protocol in clojurescript, but I am not being
able to.

I am really lost.

(ns myproject.protocols
(:refer-clojure :exclude [defprotocol])
(:require [cljs.core.typed :as t :include-macros true]))

(t/defprotocol A
(fmap [fv g :- (t/All [x y] (t/Fn [x -> y]))]
[fv g :- (t/All [x y] (t/Fn [x -> y])) fvs :- (t/NonEmptyColl A)]))

Can anyone help me?

Thx
Ambrose Bonnaire-Sergeant
2014-09-22 21:14:32 UTC
Permalink
I don't have time to check if this works in ClojureScript, but this
equivalent should work in Clojure.

(defprotocol A
([a b] fmap
[fv g :- [x -> y]] :- Result
[fv g :- [x -> y] fvs :- (NonEmptyColl x)] :- Result))
Post by Pedro Viegas
Hi! I am trying to annotate a protocol in clojurescript, but I am not
being able to.
I am really lost.
(ns myproject.protocols
(:refer-clojure :exclude [defprotocol])
(:require [cljs.core.typed :as t :include-macros true]))
(t/defprotocol A
(fmap [fv g :- (t/All [x y] (t/Fn [x -> y]))]
[fv g :- (t/All [x y] (t/Fn [x -> y])) fvs :- (t/NonEmptyColl A)]))
Can anyone help me?
Thx
Pedro Viegas
2014-09-22 21:24:27 UTC
Permalink
Thanks, probably I am requiring the wrong namespace, because I am getting:

Type Error (myproject.protocols:4:1) Found untyped var:
cljs.core.typed/defprotocol

in: cljs.core.typed/defprotocol

On Monday, September 22, 2014 6:14:53 PM UTC-3, Ambrose Bonnaire-Sergeant
Post by Ambrose Bonnaire-Sergeant
I don't have time to check if this works in ClojureScript, but this
equivalent should work in Clojure.
(defprotocol A
([a b] fmap
[fv g :- [x -> y]] :- Result
[fv g :- [x -> y] fvs :- (NonEmptyColl x)] :- Result))
Post by Pedro Viegas
Hi! I am trying to annotate a protocol in clojurescript, but I am not
being able to.
I am really lost.
(ns myproject.protocols
(:refer-clojure :exclude [defprotocol])
(:require [cljs.core.typed :as t :include-macros true]))
(t/defprotocol A
(fmap [fv g :- (t/All [x y] (t/Fn [x -> y]))]
[fv g :- (t/All [x y] (t/Fn [x -> y])) fvs :- (t/NonEmptyColl A)]))
Can anyone help me?
Thx
Ambrose Bonnaire-Sergeant
2014-09-22 21:27:24 UTC
Permalink
Oh it's much more likely that defprotocol isn't implemented yet for
ClojureScript. Hope to fix this soon.
Post by Pedro Viegas
cljs.core.typed/defprotocol
in: cljs.core.typed/defprotocol
On Monday, September 22, 2014 6:14:53 PM UTC-3, Ambrose Bonnaire-Sergeant
Post by Ambrose Bonnaire-Sergeant
I don't have time to check if this works in ClojureScript, but this
equivalent should work in Clojure.
(defprotocol A
([a b] fmap
[fv g :- [x -> y]] :- Result
[fv g :- [x -> y] fvs :- (NonEmptyColl x)] :- Result))
Post by Pedro Viegas
Hi! I am trying to annotate a protocol in clojurescript, but I am not
being able to.
I am really lost.
(ns myproject.protocols
(:refer-clojure :exclude [defprotocol])
(:require [cljs.core.typed :as t :include-macros true]))
(t/defprotocol A
(fmap [fv g :- (t/All [x y] (t/Fn [x -> y]))]
[fv g :- (t/All [x y] (t/Fn [x -> y])) fvs :- (t/NonEmptyColl A)]))
Can anyone help me?
Thx
Pedro Viegas
2014-09-22 22:09:22 UTC
Permalink
Oh, anyways, I saw that ann-protocol is there, but couldn't find any
example using it with multiple arity, like my case.

Would it be possible to help me with an example?


On Monday, September 22, 2014 6:27:44 PM UTC-3, Ambrose Bonnaire-Sergeant
Post by Ambrose Bonnaire-Sergeant
Oh it's much more likely that defprotocol isn't implemented yet for
ClojureScript. Hope to fix this soon.
Post by Pedro Viegas
cljs.core.typed/defprotocol
in: cljs.core.typed/defprotocol
On Monday, September 22, 2014 6:14:53 PM UTC-3, Ambrose Bonnaire-Sergeant
Post by Ambrose Bonnaire-Sergeant
I don't have time to check if this works in ClojureScript, but this
equivalent should work in Clojure.
(defprotocol A
([a b] fmap
[fv g :- [x -> y]] :- Result
[fv g :- [x -> y] fvs :- (NonEmptyColl x)] :- Result))
Post by Pedro Viegas
Hi! I am trying to annotate a protocol in clojurescript, but I am not
being able to.
I am really lost.
(ns myproject.protocols
(:refer-clojure :exclude [defprotocol])
(:require [cljs.core.typed :as t :include-macros true]))
(t/defprotocol A
(fmap [fv g :- (t/All [x y] (t/Fn [x -> y]))]
[fv g :- (t/All [x y] (t/Fn [x -> y])) fvs :- (t/NonEmptyColl A)]))
Can anyone help me?
Thx
Ambrose Bonnaire-Sergeant
2014-09-22 22:14:44 UTC
Permalink
Hopefully it's the same syntax as Clojure
http://clojure.github.io/core.typed/#clojure.core.typed/ann-protocol

Could you explain the semantics of fmap?

Thanks,
Ambrose
Post by Pedro Viegas
Oh, anyways, I saw that ann-protocol is there, but couldn't find any
example using it with multiple arity, like my case.
Would it be possible to help me with an example?
On Monday, September 22, 2014 6:27:44 PM UTC-3, Ambrose Bonnaire-Sergeant
Post by Ambrose Bonnaire-Sergeant
Oh it's much more likely that defprotocol isn't implemented yet for
ClojureScript. Hope to fix this soon.
Post by Pedro Viegas
cljs.core.typed/defprotocol
in: cljs.core.typed/defprotocol
On Monday, September 22, 2014 6:14:53 PM UTC-3, Ambrose
Post by Ambrose Bonnaire-Sergeant
I don't have time to check if this works in ClojureScript, but this
equivalent should work in Clojure.
(defprotocol A
([a b] fmap
[fv g :- [x -> y]] :- Result
[fv g :- [x -> y] fvs :- (NonEmptyColl x)] :- Result))
Post by Pedro Viegas
Hi! I am trying to annotate a protocol in clojurescript, but I am not
being able to.
I am really lost.
(ns myproject.protocols
(:refer-clojure :exclude [defprotocol])
(:require [cljs.core.typed :as t :include-macros true]))
(t/defprotocol A
(fmap [fv g :- (t/All [x y] (t/Fn [x -> y]))]
[fv g :- (t/All [x y] (t/Fn [x -> y])) fvs :- (t/NonEmptyColl A)]))
Can anyone help me?
Thx
Pedro Viegas
2014-09-22 22:27:14 UTC
Permalink
Sure, it should behave like a functor.

(ann-protocol Functor
fmap
(Fn [Functor [x -> y] -> Functor]
[Functor [x -> y] (Coll Functor) -> Functor]))

This would be the behaviour on a string:

(defn fmap-string
([fv g] (apply str (g fv)))
([fv g fvs] (apply str (apply g fv fvs))))

(fmap #(apply str "A" %&) "b" "c" "d") => "Abcd"


On Monday, September 22, 2014 7:15:05 PM UTC-3, Ambrose Bonnaire-Sergeant
Post by Ambrose Bonnaire-Sergeant
Hopefully it's the same syntax as Clojure
http://clojure.github.io/core.typed/#clojure.core.typed/ann-protocol
Could you explain the semantics of fmap?
Thanks,
Ambrose
Post by Pedro Viegas
Oh, anyways, I saw that ann-protocol is there, but couldn't find any
example using it with multiple arity, like my case.
Would it be possible to help me with an example?
On Monday, September 22, 2014 6:27:44 PM UTC-3, Ambrose Bonnaire-Sergeant
Post by Ambrose Bonnaire-Sergeant
Oh it's much more likely that defprotocol isn't implemented yet for
ClojureScript. Hope to fix this soon.
Post by Pedro Viegas
cljs.core.typed/defprotocol
in: cljs.core.typed/defprotocol
On Monday, September 22, 2014 6:14:53 PM UTC-3, Ambrose
Post by Ambrose Bonnaire-Sergeant
I don't have time to check if this works in ClojureScript, but this
equivalent should work in Clojure.
(defprotocol A
([a b] fmap
[fv g :- [x -> y]] :- Result
[fv g :- [x -> y] fvs :- (NonEmptyColl x)] :- Result))
Post by Pedro Viegas
Hi! I am trying to annotate a protocol in clojurescript, but I am not
being able to.
I am really lost.
(ns myproject.protocols
(:refer-clojure :exclude [defprotocol])
(:require [cljs.core.typed :as t :include-macros true]))
(t/defprotocol A
(fmap [fv g :- (t/All [x y] (t/Fn [x -> y]))]
[fv g :- (t/All [x y] (t/Fn [x -> y])) fvs :- (t/NonEmptyColl A)]))
Can anyone help me?
Thx
Ambrose Bonnaire-Sergeant
2014-09-22 22:29:54 UTC
Permalink
It gets messier if you want to abstract over the Functor, but does this
give you a start?

(ann-protocol Functor [[x :variance :covariant]]
fmap
(All [y]
(Fn [(Functor x) [x -> y] -> (Functor y)]
[(Functor x) [x -> y] (Coll (Functor y)) -> (Functor y)]))
Post by Pedro Viegas
Sure, it should behave like a functor.
(ann-protocol Functor
fmap
(Fn [Functor [x -> y] -> Functor]
[Functor [x -> y] (Coll Functor) -> Functor]))
(defn fmap-string
([fv g] (apply str (g fv)))
([fv g fvs] (apply str (apply g fv fvs))))
(fmap #(apply str "A" %&) "b" "c" "d") => "Abcd"
On Monday, September 22, 2014 7:15:05 PM UTC-3, Ambrose Bonnaire-Sergeant
Hopefully it's the same syntax as Clojure http://clojure.github.io/core.
typed/#clojure.core.typed/ann-protocol
Could you explain the semantics of fmap?
Thanks,
Ambrose
Post by Pedro Viegas
Oh, anyways, I saw that ann-protocol is there, but couldn't find any
example using it with multiple arity, like my case.
Would it be possible to help me with an example?
On Monday, September 22, 2014 6:27:44 PM UTC-3, Ambrose
Post by Ambrose Bonnaire-Sergeant
Oh it's much more likely that defprotocol isn't implemented yet for
ClojureScript. Hope to fix this soon.
Post by Pedro Viegas
cljs.core.typed/defprotocol
in: cljs.core.typed/defprotocol
On Monday, September 22, 2014 6:14:53 PM UTC-3, Ambrose
Post by Ambrose Bonnaire-Sergeant
I don't have time to check if this works in ClojureScript, but this
equivalent should work in Clojure.
(defprotocol A
([a b] fmap
[fv g :- [x -> y]] :- Result
[fv g :- [x -> y] fvs :- (NonEmptyColl x)] :- Result))
Post by Pedro Viegas
Hi! I am trying to annotate a protocol in clojurescript, but I am
not being able to.
I am really lost.
(ns myproject.protocols
(:refer-clojure :exclude [defprotocol])
(:require [cljs.core.typed :as t :include-macros true]))
(t/defprotocol A
(fmap [fv g :- (t/All [x y] (t/Fn [x -> y]))]
[fv g :- (t/All [x y] (t/Fn [x -> y])) fvs :- (t/NonEmptyColl A)]))
Can anyone help me?
Thx
Pedro Viegas
2014-09-23 13:25:32 UTC
Permalink
Yes it does! Thanks a lot for the quick reply.


On Monday, September 22, 2014 7:30:15 PM UTC-3, Ambrose Bonnaire-Sergeant
Post by Ambrose Bonnaire-Sergeant
It gets messier if you want to abstract over the Functor, but does this
give you a start?
(ann-protocol Functor [[x :variance :covariant]]
fmap
(All [y]
(Fn [(Functor x) [x -> y] -> (Functor y)]
[(Functor x) [x -> y] (Coll (Functor y)) -> (Functor y)]))
Post by Pedro Viegas
Sure, it should behave like a functor.
(ann-protocol Functor
fmap
(Fn [Functor [x -> y] -> Functor]
[Functor [x -> y] (Coll Functor) -> Functor]))
(defn fmap-string
([fv g] (apply str (g fv)))
([fv g fvs] (apply str (apply g fv fvs))))
(fmap #(apply str "A" %&) "b" "c" "d") => "Abcd"
On Monday, September 22, 2014 7:15:05 PM UTC-3, Ambrose Bonnaire-Sergeant
Hopefully it's the same syntax as Clojure http://clojure.github.io/core.
typed/#clojure.core.typed/ann-protocol
Could you explain the semantics of fmap?
Thanks,
Ambrose
Post by Pedro Viegas
Oh, anyways, I saw that ann-protocol is there, but couldn't find any
example using it with multiple arity, like my case.
Would it be possible to help me with an example?
On Monday, September 22, 2014 6:27:44 PM UTC-3, Ambrose
Post by Ambrose Bonnaire-Sergeant
Oh it's much more likely that defprotocol isn't implemented yet for
ClojureScript. Hope to fix this soon.
Post by Pedro Viegas
cljs.core.typed/defprotocol
in: cljs.core.typed/defprotocol
On Monday, September 22, 2014 6:14:53 PM UTC-3, Ambrose
Post by Ambrose Bonnaire-Sergeant
I don't have time to check if this works in ClojureScript, but this
equivalent should work in Clojure.
(defprotocol A
([a b] fmap
[fv g :- [x -> y]] :- Result
[fv g :- [x -> y] fvs :- (NonEmptyColl x)] :- Result))
Post by Pedro Viegas
Hi! I am trying to annotate a protocol in clojurescript, but I am
not being able to.
I am really lost.
(ns myproject.protocols
(:refer-clojure :exclude [defprotocol])
(:require [cljs.core.typed :as t :include-macros true]))
(t/defprotocol A
(fmap [fv g :- (t/All [x y] (t/Fn [x -> y]))]
[fv g :- (t/All [x y] (t/Fn [x -> y])) fvs :- (t/NonEmptyColl A)]))
Can anyone help me?
Thx
Loading...