I stumbled across this idea when Markus Gaelli chose it as a PhD topic about ten years ago (man, I'm old). The main idea was not to provide tests, but examples that happened to have assertions. The goal was twofold: (1) provide live documentation with real objects, (2) provide another way of composing tests.
There was a presentation of the Pyret language at SCRIPT workshop last week.
This way of coupling unit tests with functions is indeed interesting.
One the one hand I feel it's like a mixing of concerns, on the other hand it's push unit-tests into the language.
The funny part is that the examples provided are used to type the function:
fun id(x):
x
where:
id(3) is 3
id("bla") is "bla"
end
is typed as 'a -> 'a whereas:
fun id(x):
x
where:
id(3) is 3
end
is typed as int -> int