These are chat archives for ramda/ramda

16th
May 2015
David Chambers
@davidchambers
May 16 2015 01:27

Do these type signatures look correct?

//# Maybe#ap :: Maybe (a -> b) => Maybe a -> Maybe b
//# Either#ap :: Either a (b -> c) => Either a b -> Either a c

I’m using => because I’d like to include this in the signatures somehow. The type of this appears to the left of the arrow; the types of the method’s arguments and the return value appear to the right of the arrow. For example:

//# Array#filter :: [a] => (a -> Boolean) -> [a]

I’m not asking about the => syntax (though feedback is welcome), I’d like to know whether the ap signatures are correct (given the made-up syntax).

Chet Harrison
@ChetHarrison
May 16 2015 01:41
Progress. But could use some guidance. I now have a function that takes the old appBus registry and any time something new is added it clones the old version and returns it with the newly registered object.
The idea is to construct the registry and freeze it
But I'm generating a lot of obj in the process. Should I null out the old registry when I create the new one?
I'm only using const as a way of forcing no mutation
Hardy Jones
@joneshf
May 16 2015 01:45
@paldepind no problem, I didn't really know abotu it until recently, so my understanding might not be 100%
@buzzdecafe anything by Oleg Kiselyov :)
@buzzdecafe his finally tagless paper pretty well covers the ideas, also any of the talks by Simon Peyton-Jones that have to do with the expression problem are very approachable resources
Scott Sauyet
@CrossEye
May 16 2015 01:46
@davidchambers: The Maybe one looks right. I'm not following Either. Is the => placed correctly?
Scott Sauyet
@CrossEye
May 16 2015 01:48
@ChetHarrison: Are you using something like assoc/assocPath to update? This should reduce the number of created objects.
David Chambers
@davidchambers
May 16 2015 01:48
@CrossEye: I think so. In x.ap(y), x is a value of type Either a (b -> c). If x is a Right its value must be a unary function, no?
Hardy Jones
@joneshf
May 16 2015 01:48
@buzzdecafe also see object algebras and the paper associated with it: https://www.cs.utexas.edu/~wcook/Drafts/2012/ecoop2012.pdf
Scott Sauyet
@CrossEye
May 16 2015 01:49
@davidchambers: Starting to see....
Hardy Jones
@joneshf
May 16 2015 01:49
@buzzdecafe finally the GoF Interpreter pattern. though most of the examples are pretty bad for that though.
Scott Sauyet
@CrossEye
May 16 2015 01:51
@davidchambers: Yes, I get it, and yes, it looks right to me.
David Chambers
@davidchambers
May 16 2015 01:52
Okay. Thanks. :)
Chet Harrison
@ChetHarrison
May 16 2015 02:04
Hmm @CrossEye thanks! Have not looked into to those. Thanks for the tip.
I Been wondering when to break out the monads.
Michael Hurley
@buzzdecafe
May 16 2015 13:47

@joneshf thanks, i've added your recommendations to my list.

anything by Oleg Kiselyov

Like The Reasoned Schemer for example? :smile:

Simon Friis Vindum
@paldepind
May 16 2015 14:12
Why is R.__ two underscores?
Brandon Wilhite
@JediMindtrick
May 16 2015 14:17
LiveScript looks pretty awesome, are there any other good languages out there that transpile down to javascript out there? One other requirement is that Node/iojs can be a dependency (for the compiling), but prefer not to deal with other languages.
I.e. clojurescript is out b/c I have to deal with the JVM and clojure build chain.
Simon Friis Vindum
@paldepind
May 16 2015 14:17
@JediMindtrick PureScript. I haven't tried it. But people tell me it's quite awesome.
Brandon Wilhite
@JediMindtrick
May 16 2015 14:19
@paldepind thanks
Michael Hurley
@buzzdecafe
May 16 2015 14:19

Why is R. two underscores?

I believe that is because some of us like to "install" ramda functions onto the global object. But we don't wanna clobber anything that's liable to be there. Maybe not the best reason.

Simon Friis Vindum
@paldepind
May 16 2015 14:20
@JediMindtrick Last time I looked at LiveScript it was way too huge. I talked with the author and her agreed but I'm not sure if they've got it trimmed down.
@buzzdecafe Such an "installation" sounds really neat. Typing two underscores feels weird though.
It's not too bad. I was just wondering.
Michael Hurley
@buzzdecafe
May 16 2015 14:22
i believe that's why
Simon Friis Vindum
@paldepind
May 16 2015 14:22
HOW CAN I INSTALL RAMDA?!
Please.
Michael Hurley
@buzzdecafe
May 16 2015 14:23
for (f in R) {
  global[f] = R[f];
}
Raine Virta
@raine
May 16 2015 14:24
I quit doing that after getting an obscure bug where no symptom pointed to extending global being the reason
Michael Hurley
@buzzdecafe
May 16 2015 14:25
yes, there is some risk
Michael Hurley
@buzzdecafe
May 16 2015 14:25
that is why we deprecated/removed R.isNaN
Brandon Wilhite
@JediMindtrick
May 16 2015 14:25
Is the desire there to be able to just call filter() instead of R.filter()?
Michael Hurley
@buzzdecafe
May 16 2015 14:25
@JediMindtrick exactly
Simon Friis Vindum
@paldepind
May 16 2015 14:27
I'll have to try that.
Brandon Wilhite
@JediMindtrick
May 16 2015 14:28
I know eval is evil...but...you could do something similar with that and I think avoid some of the weirdness you can sometimes see with that method.
I've done something like that before awhile back.
But I stopped b/c it just felt wrong.
Simon Friis Vindum
@paldepind
May 16 2015 14:29
Might be slightly safer:
for (f in R) {
  if (global[f] === undefined) global[f] = R[f];
}
Michael Hurley
@buzzdecafe
May 16 2015 14:29
yes
then you may get weird bugs in the other direction though
Simon Friis Vindum
@paldepind
May 16 2015 14:31
Might be slightly safer:
for (f in R) {
  if (global[f] === undefined) global[f] = R[f];
  else console.warning('R.' + f + ' has not been injected into global scope');
}
Brandon Wilhite
@JediMindtrick
May 16 2015 14:31
Am I wrong, or does the ES6 module syntax also fail to provide a way to do this? Which is a shame.
Michael Hurley
@buzzdecafe
May 16 2015 14:32
you could always wrap your entire script with(R) ...
Simon Friis Vindum
@paldepind
May 16 2015 14:32
That is certainly worse. You can't use strict for instance.
Michael Hurley
@buzzdecafe
May 16 2015 14:33
:smiling_imp:
i am joking of course
Simon Friis Vindum
@paldepind
May 16 2015 14:33
:)
Michael Hurley
@buzzdecafe
May 16 2015 14:33
@raine nice work. ramda-cli is slick!
Hardy Jones
@joneshf
May 16 2015 15:04
@buzzdecafe :)
Michael Hurley
@buzzdecafe
May 16 2015 15:08
hey @joneshf I am very interested in understanding how to manipulate these functions algebraically.
seems to me that it bumps into some problems in reality
such as when you are rewriting a composition
you may get the equivalent result, but not the optimal path to the result
but that is another branch of research :smile:
Raine Virta
@raine
May 16 2015 15:54
what do you imagine this would do? $ echo [1,2,3] | R 'map multiply 2' sum
Michael Hurley
@buzzdecafe
May 16 2015 15:55
12
Raine Virta
@raine
May 16 2015 15:59
yep, multiple arguments are composed from left to right. figured it's a nice shorthand for R 'pipe((map multiply 2), sum)'
Simon Friis Vindum
@paldepind
May 16 2015 16:25
I'm rewriting code to use R.evolve. It's awesome.
Michael Hurley
@buzzdecafe
May 16 2015 16:25
any examples?
Simon Friis Vindum
@paldepind
May 16 2015 16:28

I've for instance turned this:

return {nextId: model.nextId + 1,
        counters: R.append([model.nextId, counter.init(0)], model.counters)}

Into this:

return R.evolve({nextId: R.add(1),
                counters: R.append([model.nextId, counter.init(0)]), model);
Michael Hurley
@buzzdecafe
May 16 2015 16:30
:+1:
Simon Friis Vindum
@paldepind
May 16 2015 16:32

This one is even better:

return {nextId: model.nextId, counters: R.tail(model.counters)};

Into this:

return R.evolve({counters: R.tail}, model);

With R.evolve I wont have to name the property I'm not changing.

It's way more readable.
Hardy Jones
@joneshf
May 16 2015 16:56
@buzzdecafe i'm not sure i follow, can you give an example?
Michael Hurley
@buzzdecafe
May 16 2015 16:57
for example consider query optimization
there are a number of heuristics to guide it
like select then project
and the heuristics are pretty good
but don't guarantee that you will get the optimal query strategy
likewise with functional algebra i expect
since it is not concerned with how you get the answer, just that the answer is correct
Hardy Jones
@joneshf
May 16 2015 17:07
hmm, so are you concerned with using algebra for optimization (not necessarily query opt.)?
Michael Hurley
@buzzdecafe
May 16 2015 17:08
in the context of microkanren yes
Hardy Jones
@joneshf
May 16 2015 17:08
ah
well, I guess it depends on what you consider optimal.
Michael Hurley
@buzzdecafe
May 16 2015 17:08
right!
Hardy Jones
@joneshf
May 16 2015 17:08
for some definitions it might not be possible to optimize, and for others it could be
Also, there's no reason that there would be a single optimal solution. You might have an entire family of optimal solutions.
depending on what your feasible solution space is.
Michael Hurley
@buzzdecafe
May 16 2015 17:10
yep, or sometimes relaxing certain constraints may get you within some \epsilon of an optimum
Hardy Jones
@joneshf
May 16 2015 17:10
yeah
i think...
Michael Hurley
@buzzdecafe
May 16 2015 17:10
this stuff fascinates me
Hardy Jones
@joneshf
May 16 2015 17:11
If you can transform your microkanren optimization into a system of linear equations, then you can actually optimize it.
and for sure arrive at some optimal solution, assuming it is a feasible problem, and bounded.
Michael Hurley
@buzzdecafe
May 16 2015 17:12
those are pretty big constraints you tacked on :smile:
Hardy Jones
@joneshf
May 16 2015 17:12
well, maybe
maybe not :)
i feel like this might already have some research in it
maybe look into compiler optimization, term rewriting, and similar ideas
Michael Hurley
@buzzdecafe
May 16 2015 17:13
yeah, i remember scratching the surface of it in grad school
Hardy Jones
@joneshf
May 16 2015 17:14
of course, even if you can translate it, it might be NP to solve it
so you might even look into approximating an optimum.
like you said, some ϵ of an optimum
!!
Michael Hurley
@buzzdecafe
May 16 2015 17:16
it depends on how you specify the problem. If within epsilon is ok, then NP may become P for the purposes of that search
Hardy Jones
@joneshf
May 16 2015 17:16
gitter supports !
Michael Hurley
@buzzdecafe
May 16 2015 17:17
:epsilon:
Hardy Jones
@joneshf
May 16 2015 17:17
<dollar><dollar>\epsilon<dollar><dollar>
Michael Hurley
@buzzdecafe
May 16 2015 17:17
excellent!
λ
Hardy Jones
@joneshf
May 16 2015 17:23
alright, apparently it's katex?
Michael Hurley
@buzzdecafe
May 16 2015 17:26
KaTeX parse error: Expected 'EOF', got '\choose' at position 30: m_0^n n \choose̲ 2 : \lambda_n = \sum_0^n n \choose 2 
Hardy Jones
@joneshf
May 16 2015 17:28
yeah, it seems to be missing quite a few things.
Michael Hurley
@buzzdecafe
May 16 2015 17:29
maybe i have to add some macros in the header of my comment ....
Hardy Jones
@joneshf
May 16 2015 17:30
KaTeX parse error: Expected '}', got '\over' at position 8: {n \over̲ 2}: {n \over 2}
Michael Hurley
@buzzdecafe
May 16 2015 17:31
1k
sorry @joneshf no combinatorics supported
Hardy Jones
@joneshf
May 16 2015 17:33
Maybe gitter is using an older version or something?
Hardy Jones
@joneshf
May 16 2015 18:12
so anyway
how would you define optimality with microkanren?
Michael Hurley
@buzzdecafe
May 16 2015 18:15
idk yet! moving in too many directions at once.
have bookmarks in all sorts of projects
Michael Hurley
@buzzdecafe
May 16 2015 20:32
i've set up a google groups mailing list for any interested parties:
https://groups.google.com/forum/#!forum/ramda