fantasyland / fantasy-land

Specification for interoperability of common algebraic structures in JavaScript
MIT License
10.11k stars 375 forks source link

Help understanding use of identity in Traversable laws #306

Closed jlrwi closed 5 years ago

jlrwi commented 5 years ago

The Composition law for Traversable uses the identity function (x => x) as an argument where a function of type a -> f b is expected. This has me confused - using F.of or G.of to lift the value into the desired Applicative would fit the type signature, but that's not how it's written.

I'm trying to educate myself by implementing traverse for simple types like Identity and Maybe, and I'm not sure if my implementation of traverse is wrong, or if my implementation of the test is wrong, or both.

safareli commented 5 years ago

using id in traverse means the traversable already has values of type f b in it. for example if you have Array (Maybe Int) and use traverse with id you would get Maybe (Array int)

jlrwi commented 5 years ago

That was the clue that helped me undo the knot in my brain. (After several more hours of puzzling.) Thanks!