funcool

A channel for discussing and asking questions about Funcool libraries https://github.com/funcool/
2015-12-04T09:02:53.000123Z

Hello. I'm newbie to Clojure, and trying to use https://github.com/funcool/cats So I create a new project with lein, then add [funcool/cats "1.1.0"] as dependency in project.clj, and my core.cljgets as simple as: (ns core-clojure.core (:require [cats.core :as m]) (:gen-class)) (defn -main "Main" [& args] (m/mappend [1 2 3] [4 5 6]) (println "Hello, World!")) which gives following error when running like lein run from command line: Exception in thread "main" java.lang.IllegalArgumentException: No context is set and it can not be automatically resolved., compiling:(/tmp/form-init1960448665477151794.clj:1:73) Any ideas?

jaen 2015-12-04T09:09:57.000125Z

@lizzie: IIRC by default core datatypes have no protocols implemented for them, so they can't act like monoids and whatnot.

👍 1
jaen 2015-12-04T09:10:23.000126Z

If you want that behaviour you have to explicitly require cats.builtin

jaen 2015-12-04T09:10:52.000127Z

Which has some default implementation of those protocols.

jaen 2015-12-04T09:11:37.000128Z

If you want to see how they behave here are the implementations - https://github.com/funcool/cats/blob/master/src/cats/builtin.cljc

jaen 2015-12-04T09:13:22.000131Z

I guess it's done this way because someone might want them to behave differently - for example the monoid implementation of map does shallow merging, someone might want recursive merging for example.

niwinz 2015-12-04T09:20:07.000132Z

+1 @jaen

2015-12-04T09:20:54.000133Z

Thank you for the explanation. I will take a look into the implementation.

jaen 2015-12-04T09:23:55.000134Z

For example if you modify the map monoid for recursive merging you can get pretty nice validators with maps and sets with the validation applicative in only a few tens of lines of code.

jaen 2015-12-04T09:25:30.000135Z

So that's probably why the default implementation is something you have to knowingly require - if they suit you, require them and use them, otherwise write your own.

jaen 2015-12-04T09:26:47.000136Z

@niwinz: as I understand there's no way to require only some default implementations right now, yes?

niwinz 2015-12-04T09:27:36.000137Z

At this moment it is not possible

niwinz 2015-12-04T09:27:55.000138Z

but I think you can overwrite it with own impl without problem...

niwinz 2015-12-04T09:28:42.000139Z

Maybe in a future we can think modularize that part, but at this moment we found the current solution a good start point and it works pretty well

jaen 2015-12-04T09:29:07.000140Z

Yeah, I agree, I was just curious, really.

niwinz 2015-12-04T09:30:02.000142Z

nice, in any case its really great suggestion, we haven't though about...

niwinz 2015-12-04T21:40:02.000143Z

[ann]: promesa 0.6.0 is released yesterday, now is cross-platform (clj and cljs) and can be used in almost the same way in the both platforms

niwinz 2015-12-04T21:40:17.000144Z

promissum should now be considered deprecated in favor of promesa

kenny 2015-12-04T21:52:52.000145Z

@niwinz: I believe your pre-condition for repeat in beicon is incorrect. It should be on n, not v.

(defn repeat
  "Generates an observable sequence that repeats the
  given element."
  ([v]
   (repeat v -1))
  ([v n]
   {:pre [(number? v)]}
   (js/Rx.Observable.repeat v n)))

niwinz 2015-12-04T21:53:15.000146Z

You are completly right!

niwinz 2015-12-04T21:53:22.000147Z

I'll fix it ASAP

kenny 2015-12-04T21:53:27.000148Z

Thanks :simple_smile:

niwinz 2015-12-04T21:56:04.000149Z

0.3.0-SNAPSHOT is just released with the fix

niwinz 2015-12-04T21:57:03.000150Z

Thanks for report it!

kenny 2015-12-04T21:58:12.000151Z

👍