Fork me on GitHub
#funcool
<
2015-10-21
>
blendmaster15:10:40

heyo, is there any existing sugar for (m/fapply (m/fmap curried+ (just 1)) (just 2) (just 3)), i.e. being able to write (some-sugar curried+ (just 1) (just 2) (just 3))?

blendmaster15:10:58

essentially, idiom brackets from the original applicative paper

tcsavage16:10:31

Doesn’t look like it but one could probably write a simple macro wrapping alet

tcsavage16:10:00

Would something like this do the trick?

(defmacro idiom
  [f & as]
  (let [args (map (fn [x] [(gensym) x]) as)]
    `(m/alet [~@(apply concat args)]
      (~f ~@(map first args)))))

blendmaster18:10:15

yep, that looks reasonable. I was mainly wondering if there was such a thing hidden in the library already.

blendmaster18:10:54

(defn ap [f arg & args]
  (apply m/fapply (m/fmap f arg) args))

dialelo20:10:05

we can currently lift a function to a monadic context with lift-m and we're working on a lift-a version https://github.com/funcool/cats/pull/113

dialelo20:10:34

for the moment you can wrap alet as tcsavage suggests

dialelo20:10:49

@blendmaster: the ap combinator could be a great addition to cats

blendmaster20:10:20

I like it semantically, but it could certainly use some syntax bikeshedding

dialelo21:10:03

thanks for the references, i'll look into those

dialelo21:10:10

we've tried to design the sugar (`mlet` and alet) to be idiomatic