-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot use laws/functor to test composition property #172
Comments
Re: statement before 🍭 |
Tbh: i wonder if we should track all the law issues in one issue. I bet there are quite a few. |
Perhaps. I'm now questioning the value of these modules. Since in many cases we need to provide a value (e.g. |
FWIW, composition doesn't really need to be proved:
I wonder, should the spec should even mention it as a requirement? |
@joneshf it would be nice if you create an issue for that 🍭 |
Are you sure this applies in case of JS? Consider this "functor" created from Promise: Promise.prototype.map = function(f) { return this.then(f) }
const promise = Promise.resolve(1)
// always true, because it's impossible to create promise of promise
promise.map(x => x) === promise
const g = x => Promise.of(x)
const f = promise => promise.map(x => x)
// right hand side will blow up
promise.map(x => f(g(x))) === promise.map(g).map(f) So if we remove second law, this incorrect functor will become technically correct. |
I don't have much want for it to be removed. So, if it's worse, then no change :). But honestly, you can do similar hacks in haskell with I mean, the data type's map procedure could look at the current timestamp and throw an exception only when it is congruent to 0 mod 123456789. You'd almost never see it blow up in practice, so both laws would pass, effectively, all of the time. Did the second law help us catch the problem? |
I wish we had a law that enforces parametricity somehow :) I think Fantasy Land is often used by beginners who only start to learn FP, so it would be cool if only by obeying the laws they would fall into pit of success, even if they don't understand why certain law exists. I'm to be honest one of those beginners :) |
TIL: Parametricity also makes any function |
identityʹ
:composition
:Consider
a
incomposition
:Assume a proof for
compose(identity)(identity) = identity
:The identity property tells us that
t(x)[map](identity) = t(x)
, so:Consider
b
incomposition
:The identity property tells us that
t(x)[map](identity) = t(x)
, so:I think all we're actually proving is
compose(identity)(identity) = identity
, which isn't at all what we're hoping to prove. 😜For
composition
to be useful I think it needs to takef :: b -> c
andg :: a -> b
as arguments.The text was updated successfully, but these errors were encountered: