-
-
Notifications
You must be signed in to change notification settings - Fork 110
Document iftype #580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Document iftype #580
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -27,4 +27,5 @@ quiescence | |
| quiescent | ||
| unmuted | ||
| unmutes | ||
| iftype | ||
| Zulip | ||
This file contains hidden or 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,15 @@ | ||
| trait Animal | ||
| class Cat is Animal | ||
| class Dog is Animal | ||
|
|
||
| actor Main | ||
| new create(env: Env) => | ||
| greet[Cat](env) | ||
| greet[Dog](env) | ||
|
|
||
| fun greet[A: Animal](env: Env) => | ||
| iftype A <: Cat then | ||
| env.out.print("meow") | ||
| else | ||
| env.out.print("woof") | ||
| end | ||
This file contains hidden or 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,23 @@ | ||
| trait Animal | ||
|
|
||
| class Cat is Animal | ||
| var _name: String = "Cat" | ||
|
|
||
| fun box name(): String => _name | ||
| fun ref set_name(name': String) => _name = name' | ||
|
|
||
| actor Main | ||
| new create(env: Env) => | ||
| let cat: Cat ref = Cat | ||
| maybe_rename[Cat ref](cat, env) | ||
|
|
||
| let cat2: Cat val = Cat | ||
| maybe_rename[Cat val](cat2, env) | ||
|
|
||
| fun maybe_rename[A: Animal](a: A, env: Env) => | ||
| iftype A <: Cat ref then | ||
| a.set_name("Kitty") | ||
| env.out.print(a.name()) | ||
| elseif A <: Cat box then | ||
| env.out.print(a.name()) | ||
| end |
This file contains hidden or 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,19 @@ | ||
| trait Animal | ||
| class Cat is Animal | ||
| class Dog is Animal | ||
| class Fish is Animal | ||
|
|
||
| actor Main | ||
| new create(env: Env) => | ||
| describe[Cat](env) | ||
| describe[Dog](env) | ||
| describe[Fish](env) | ||
|
|
||
| fun describe[A: Animal](env: Env) => | ||
| iftype A <: Cat then | ||
| env.out.print("I'm a cat") | ||
| elseif A <: Dog then | ||
| env.out.print("I'm a dog") | ||
| else | ||
| env.out.print("I'm something else") | ||
| end |
This file contains hidden or 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,20 @@ | ||
| trait Animal | ||
| fun name(): String | ||
|
|
||
| class Cat is Animal | ||
| fun name(): String => "Cat" | ||
| fun purr(): String => "prrr" | ||
|
|
||
| class Dog is Animal | ||
| fun name(): String => "Dog" | ||
|
|
||
| actor Main | ||
| new create(env: Env) => | ||
| describe[Cat val](Cat, env) | ||
| describe[Dog val](Dog, env) | ||
|
|
||
| fun describe[A: Animal val](a: A, env: Env) => | ||
| env.out.print(a.name()) | ||
| iftype A <: Cat val then | ||
| env.out.print(a.purr()) | ||
| end |
This file contains hidden or 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,15 @@ | ||
| trait Animal | ||
| class Cat is Animal | ||
| class Dog is Animal | ||
|
|
||
| actor Main | ||
| new create(env: Env) => | ||
| check[Cat, Dog](env) | ||
| check[Cat, Cat](env) | ||
|
|
||
| fun check[A: Animal, B: Animal](env: Env) => | ||
| iftype (A, B) <: (Cat, Dog) then | ||
| env.out.print("cat and dog") | ||
| else | ||
| env.out.print("some other combination") | ||
| end |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.