Toot

Written by Per Vognsen on 2025-01-03 at 01:26

A nice example of parametricity is that a function signature like fn sort<T: Ord>(slice: &mut [T]) must be a permutation since you can't make new T values (without invoking UB). So a seemingly weak postcondition like is_sorted(slice) is actually a sufficient specification, assuming parametricity. Similarly, even if you're returning a new sequence, e.g. fn sort<T: Ord>(slice: &[T]) -> Vec, you'd only need to add result.len() == slice.len() to the postcondition.

=> More informations about this toot | View the thread | More toots from pervognsen@mastodon.social

Mentions

Tags

Proxy Information
Original URL
gemini://mastogem.picasoft.net/toot/113761818879121005
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
228.48071 milliseconds
Gemini-to-HTML Time
0.625166 milliseconds

This content has been proxied by September (ba2dc).