Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Functions that can be deduced by their type signature

I was introduced to this idea informally by this c++ talk Ben Deane “Using Types Effectively"

For example:

template<typename T, typename U>
T f(pair<T, U>);

can be deduced to be first.

  • What is the proper terminology for this?
  • Are there some resources to learn more?
like image 792
Tom Huntington Avatar asked Oct 19 '25 11:10

Tom Huntington


1 Answers

David Young already answered this in the comments of my other question.

Regarding functions with only one possible implementation: This is the result of something called "parametricity". Sometimes it is not only one implementation, but the collection of possible implementations is very restricted. This fact is expressed by a "free theorem." Every parametrically polymorphic function has an associated free theorem. Some resources: 1, 2, 3, 4

like image 153
Tom Huntington Avatar answered Oct 21 '25 14:10

Tom Huntington



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!