bow-swift / bow

🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
https://bow-swift.io
Other
643 stars 32 forks source link

Documentation for simulated rank-n polymorphism (aka documentation on FunctionK) #620

Closed ferranpujolcamins closed 3 years ago

ferranpujolcamins commented 3 years ago

Description

FunctionK allows us to create a class that encapsulates a polymorphic function, thus simulating a closure that is polymorphic on some of its type parameters (rank-n polymorphism). We should add a documentation page explaining this technique.

We should add some example and cover some topics like polymorphic type parameters vs bound type parameters.

Modules

Documentation

Breaking changes

None

truizlop commented 3 years ago

Agreed. Do you have something in mind? A draft or something?

ferranpujolcamins commented 3 years ago

Yeah, I'll try to come up with something.

Basically I think we can start by explaining what a regular closure is in swift and show how a class that has a function and a property for each captured parameter is isomorphic to a closure.

Then we just need to show that by making the function in our class generic over T, we can now effectively pass around a generic function like an object, i.e. we have created a polymorphic closure.

truizlop commented 3 years ago

Sounds good to me. I'm assigning this to you.

truizlop commented 3 years ago

Closed by #622