-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When typechecking "if in state" tests, do not ignore this-field types…
… that are specified in only one branch. Instead, try to pack them away (when they are consistent).
- Loading branch information
Showing
5 changed files
with
157 additions
and
35 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
Obsidian_Runtime/src/main/java/Runtime/edu/cmu/cs/obsidian/stdlib/LinkedList.obs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
main contract LinkedList[T@s] { | ||
state Empty; | ||
|
||
state HasNext { | ||
LinkedList[T@s]@Owned next; | ||
T@s value; | ||
} | ||
|
||
LinkedList@Empty() { | ||
->Empty; | ||
} | ||
|
||
|
||
transaction append(LinkedList@Owned this, T@s >> Unowned ptr) { | ||
switch this { | ||
case HasNext { | ||
next.append(ptr); | ||
} | ||
case Empty { | ||
->HasNext(value = ptr, next = new LinkedList[T@s]()); | ||
} | ||
} | ||
} | ||
|
||
transaction length(LinkedList@Owned this) returns int { | ||
switch this { | ||
case HasNext { | ||
return 1 + next.length(); | ||
} | ||
case Empty { | ||
return 0; | ||
} | ||
} | ||
} | ||
|
||
|
||
transaction nth(LinkedList@Owned this, int n) returns T@Unowned { | ||
switch this { | ||
case HasNext { | ||
if (n == 0) { | ||
return value; | ||
} | ||
else { | ||
return next.nth(n - 1); | ||
} | ||
} | ||
case Empty { | ||
revert "Can't get the nth item from an empty list."; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters