Union and intersection contracts are hard
tweag.io
tweag.io
wait, what? This does not seem right. Python can easily deserialize millions of json records per second (and that involves much more that simple validation described in the article). And this talks about Haskell, which is compiled and should be much faster.
Was the decision to be "lazy", which caused so much more complexity, caused by bad assumptions and lack of benchmarking?
> If foo is never used, the contract won’t fail the execution.
This sounds like suboptimal developer's experience, you usually want to validate everything upfront. Spending 10 minutes compiling and then failing because of typo in install location sucks.
The paper also describes function contracts, which I think simply ensure that the return types and argument types conform to a specification. This isn’t lazy, per se, but in a dynamic language you can’t check those things until you call the function. But isn’t that an obvious point?
Obviously, static analysis is possible, but the type system needs to be designed with type-checking functions in mind.
let f | ( Positive → Positive ) ∪ ( Positive → NonPositive ) = fun x ⇒ x - 7 in (f 10) + ( f 5)
Here a function is supposed to take a positive number and then return a number that's both positive and negative. That is, the intersection of the return types is the empty set and there's no possible implementation.
So it seems like arbitrary unions of multiple function types isn't a good way to represent a function type. But it's unclear why you'd expect this to work since taking the union of two functions doesn't work either. Considered as a set of (input, output) pairs, the union of two functions is often a nonfunction, mapping the same input to multiple outputs.
Consider how this works for merging dictionaries. Each key can only be mapped to one value, so you can't just take the union without deciding which input takes priority when keys overlap.
Similarly, for function overloading, either the input types don't overlap or there is some way of deciding which takes priority.
Can you elaborate on the Prolog problem so I can tell if it's a good fit? Guesser 2.0 specifically reduces the search space of naive search.
A quick google produces this example - https://en.m.wikibooks.org/wiki/Prolog/Cuts_and_Negation https://www.cs.uleth.ca/~gaur/post/prolog-cut-negation/