question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Apply composition law does not equate

See original GitHub issue

It could be that my implementation is not correct, but here’s the result of the test.

test.js

"use strict";

class Thing {
  constructor(value) {
    this.value = value;
  }
  ap(other) { return other.map(this.value); }
  map(f) { return new Thing(f(this.value)); }
}

const y = new Thing(x => x);
const left = y.ap(y.ap(y.map(f => g => x => f(g(x)))));
const right = y.ap(y).ap(y)

console.log("left === right:", left === right);
console.log("left value:", left.value.toString());
console.log("right value:", right.value.toString());

Running test.js

$ node test
left === right: false
left value: g => x => f(g(x))
right value: x => x

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
davidchamberscommented, Dec 12, 2016

Similar to Function#apply or a curried Function#call.

Don’t contaminate your thoughts with this sort of comparison. 😉

I suggest comparing ap to map. They’re very similar:

> Thing(9).map(Math.sqrt)
Thing(3)

> Thing(9).ap(Thing(Math.sqrt))
Thing(3)

The type signatures are instructive:

map :: Functor f => (a -> b) -> f a -> f b
ap  :: Apply f => f (a -> b) -> f a -> f b
1reaction
joneshfcommented, Dec 12, 2016

ap exists in Prelude as well.

λ: ap [(*10),(*100),(*1000)] [1,2,3]
[10,20,30,100,200,300,1000,2000,3000]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Function composition where two functions are not equal
Yes, you can. To satisfy these conditions, g has to be the identity map on the range of f, but you can play...
Read more >
Composition Law - an overview | ScienceDirect Topics
The composition law (s1,s2) ↦ (s1,s2) on the space of sections of π extends into a composition law on the space of sections...
Read more >
Theorem for limits of composite functions - Khan Academy
This limit would be equal to the value of f(L), where L is the limit of g(x) at x=a, ... was left out);...
Read more >
Function Composition is Associative - YouTube
Function Composition is Associative. Watch later. Share. Copy link. Info. Shopping. Tap to unmute. If playback doesn't begin shortly, ...
Read more >
6.4: Composition of Functions - Mathematics LibreTexts
Since f(x)∈B, we can apply the function g to f(x), and we obtain g(f(x)), which is an element of C. Using this process,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found