cannot use laws/functor to test composition property
See original GitHub issueconst identityʹ = t => eq => x => { const a = t(x)[map](identity); const b = t(x); return eq(a, b); };
const composition = t => eq => x => { const a = t(x)[map](compose(identity)(identity)); const b = t(x)[map](identity)[map](identity); return eq(a, b); };
Consider a
in composition
:
a = t(x)[map](compose(identity)(identity))
Assume a proof for compose(identity)(identity) = identity
:
a = t(x)[map](identity)
The identity property tells us that t(x)[map](identity) = t(x)
, so:
a = t(x)
Consider b
in composition
:
b = t(x)[map](identity)[map](identity)
The identity property tells us that t(x)[map](identity) = t(x)
, so:
b = t(x)[map](identity)
b = t(x)
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 take f :: b -> c
and g :: a -> b
as arguments.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Methods on an object created via composition can't access all ...
I was expecting john 's method isOfAge to be able to access the property isAdult , since it's in the object. However, conceptually...
Read more >Verifying inverse functions by composition - Khan Academy
Learn how to verify whether two functions are inverses by composing them. For example, are f(x)=5x-7 and g(x)=x/5+7 inverse functions?
Read more >Plugging One Function Into Another: Composition Explained
With no number to evaluate at, how do you compose the functions? Study these worked examples to learn how!
Read more >Composition of Functions - Definition, Properties and Examples
In maths, solving a composite function signifies getting the composition of two functions. A small circle (∘) is used to denote the composition...
Read more >Composition of functions - Mathcentre
We can build up complicated functions from simple functions by using the process of composition, where the output of one function becomes the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
TIL: Parametricity also makes any function
t :: (Functor f, Functor g) => f a -> g a
natural transformation. In other words just by looking at signature we gett(v.map(f)) == t(v).map(f)
for free. https://youtu.be/2LJC-XD5Ffo?t=31m22sI 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
Data.Typeable
. That doesn’t mean we need to stop believing the proof to be true. If a data type doesn’t respect parametricity, I don’t know that we should care about that data type.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?