These are chat archives for ramda/ramda

22nd
May 2015
Tobias Pflug
@gilligan
May 22 2015 05:50
@joneshf: was that meant for me? Unspecified behavior because I check what chain on Left value returns? How else could I distinguish?
Hardy Jones
@joneshf
May 22 2015 05:53
unspecified because R.identity doesn't return the right thing
Tobias Pflug
@gilligan
May 22 2015 06:00
Pretty sure it does. On my mobile, checking again later
Wait, it is totally irrelevant what R.identity returns. It is not evaluated for Left values
Tobias Pflug
@gilligan
May 22 2015 06:30
Might be better to assert chain result on Right values as that certainly is not going to change. @joneshf don't see how else this could be implemented. And still not sure what you were referring to with R.identity
Hardy Jones
@joneshf
May 22 2015 06:39

The return value of R.identity is important, and tells whether or not what you've written will have specified behavior:
https://github.com/fantasyland/fantasy-land#chain-method

Since you have:

Either.chain : Either a b => (b -> Either a c) -> Either a c
R.identity : a -> a

In order to use what you've written, you'd have to unify b with Either a c (which is fine) giving you something like:

isLeft : Either a (Either a c) -> Bool

However, if you call it with Either a b, it's unspecified what you get back, if you get anything back. It could not terminate for some reason, or throw an error since the contract was violated, or some other thing. It could even be some poor implementation that checks the value returned and wraps it if it's not an Either a b in which case this implementation surely would not work.

Let me be clear, what you've written in code is not unspecified. However, the comments about the types and the way it would most likely be used is unspecified.
Hardy Jones
@joneshf
May 22 2015 07:00
As far as how to implement what you want, you can't do that with the methods provided by the Apply hierarchy. However, you can go to the other side and use Extend.
var isLeft = function(x) {
  return x.extend(R.identity) === x;
}
Of course, I dunno that equality will work there anyway.
Tobias Pflug
@gilligan
May 22 2015 07:11
@joneshf : okay you are obviously right
@joneshf : well meh, playing types with js still sucks because nobody but your brain has to tell you you are doing it wrong ;)
Hardy Jones
@joneshf
May 22 2015 07:13
yeah, it's kind of a drag
i wonder if flow could do anything there
or ts
Tobias Pflug
@gilligan
May 22 2015 07:15
iirc flow is not overly useful until you break js compatibility and add signatures in your function declaration
support to parse signatures/type hints in comments would have been good
there is a possibility I am completely mixing this up though - I haven't actually used flow myself. Only talked to a colleague of mine who tried it
@joneshf uhm, Either does not implement Extend does it
Hardy Jones
@joneshf
May 22 2015 07:21
It can, and if it doesn't, it should.
Tobias Pflug
@gilligan
May 22 2015 07:22
not yet
Tobias Pflug
@gilligan
May 22 2015 07:27
@joneshf little confused about Extend right now .. extend :: Extend E => E v -> (f -> v) -> v would that be correct?
Hardy Jones
@joneshf
May 22 2015 07:27
what is E?
oh
Almost.
extend :: Extend E => E v -> (E v -> u) -> E u
Tobias Pflug
@gilligan
May 22 2015 07:35
aah, ok.. function is applied on unboxed value, ok
Hardy Jones
@joneshf
May 22 2015 07:39
it should be applied to the whole value, and wrapped up again.
Left.prototype.extend = function(_) {
  return this;
};
Right.prototype.extend = function(f) {
  return Right(f(this));
};
Tobias Pflug
@gilligan
May 22 2015 07:45
yup
want to do a pull request ?
Hardy Jones
@joneshf
May 22 2015 07:47
go for it
Tobias Pflug
@gilligan
May 22 2015 08:00
ramda/ramda-fantasy#44
Raine Virta
@raine
May 22 2015 08:03
:point_up: May 22 2015 10:11 AM your brain or @joneshf
Tobias Pflug
@gilligan
May 22 2015 08:07
;]
actually think it would be nice to have haskell'ish type signatures everywhere - would help /me/ at least ;-]
Tobias Pflug
@gilligan
May 22 2015 10:55
@joneshf pull request was merged already