Add contract checking for functions passed as arguments to pyramda functions
Currently, there are no checks in place to ensure that functions passed as arguments to pyramda functions conform to a specific contract in terms of signature and return values. For example, the function passed to pyramda's flip function must accept atleast two arguments or the function passed to filter must be a predicate.
Libraries such as sanctuary might provide a good paradigm for implementing such contract checking
My experience with contracts mostly comes from the Racket programming language. The Racket Guide has a document describing contracts called Simple Contracts on Functions, which covers most of what we want. There's a few gotchas involved though:
- Some generic functions could use parametric contracts which enforce proper handling of type variables. For instance,
mapwith a parametric contract wouldn't be able to insert random elements into the array it's given without violating the contract. - Currying messes with quite a bit of this. Some functions can have their arguments checked eagerly, but others need to wrap them as higher order values for later checks in the implementation. Arity checking in contracts gets a little tricky too. There's also dependent contracts where checking some of the arguments requires knowing other arguments, such as checking that a
zip_with : (a -> b -> c) -> [a] -> [b] -> [c]function is given arrays of equal length.
We might have to roll our own library for this, I've not yet found a python contracts implementation that handles all of the above.
This will be fun to work on!