Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/refinement.html.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#lang pollen

◊p{
As students learn to work with invariants, it is helpful and
instructive to express them directly in the source program. Pyret
supports ◊em{refinments} to enable this. Currently, refinements in
Pyret are checked dynamically, so that students don't have to go
through the hurdles of convincing a proof-assistant that the
program is compliant, and they can get concrete examples of
failures.
}
44 changes: 44 additions & 0 deletions examples/refinement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const example = `use context starter2024

fun is-sorted-ascending(l :: List<Number>) -> Boolean:
cases (List) l:
| empty => true
| link(f, r) =>
cases (List) r:
| empty => true
| link(fr, rr) =>
if f <= fr:
is-sorted-ascending(r)
else:
false
end
end
end
end

fun insert(n :: Number,
l :: List%(is-sorted-ascending))
-> List%(is-sorted-ascending):
cases (List) l:
| empty => [list: n]
| link(f, r) =>
if n < f: link(n, l)
else: link(f, insert(n, r))
end
end
end

check:
insert(1, [list: 2, 3, 4]) is [list: 1, 2, 3, 4]
insert(1, [list: 3, 2, 4]) raises "predicate"
end

# Uncomment and run the next line to see the error message!
# insert(1, [list: 3, 2, 4])
`;

export const refinement = {
definitionsAtLastRun: example,
editorContents: example,
replContents: ""
};
1 change: 1 addition & 0 deletions index.html.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
("tables" . "Tables")
("data" . "Data Structures")
("lambdas" . "Lambdas")
("refinement" . "Type Refinements")
("oop" . "Object-Oriented Programming")
("forloops" . "Loops")
("mutation" . "Mutation and State")
Expand Down