2 ms·
Well, you can create a SortedList type that is only returned from sort functions, so you can write functions that only accept sorted lists.
by wtetzner 8y ago
Well, you can create a SortedList type that is only returned from sort functions, so you can write functions that only accept sorted lists.
- yogthos 8y agoIt's not a question of whether you can do it in principle or not. My point was that I don't think it's an effective approach for creating such specifications compared to the alternatives such as runtime contracts.
- wtetzner 8y agoWhy is that? In fact, I would argue you want both. You want to use a contract to check the incoming data, but once it's been checked, you'd want to wrap it in a type that guarantees the property is set. Otherwise, you have to iterate over a potentially very large set of data to check if it's sorted every time you want to use a function that has that contract.