opaque types #2825
jleahred
started this conversation in
Ideas & suggestions
opaque types
#2825
Replies: 2 comments 1 reply
-
We do have opaque types! pub opaque type IntNot0 {
IntNot0(i: Int)
} The tour currently is missing a page on them, sorry about that. |
Beta Was this translation helpful? Give feedback.
0 replies
-
@jleahred Does this answer your question? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
A very cool language, very nice job
Wouldn't it be interesting to have opaque types?
Let me give you an example.
Imagine we want a type of integers but not zero
It could be represented as...
In this way, we could define a type that is an integer except for zero, and it is during the creation of the type where the verification must be performed to ensure correctness
Because the "content" is private, there is only one way to create values of this types, with a "creation" function that will verify (in this case) that value never is zero
Now we could have a function with signature...
We don't need to check in all uses that is not zero, checking is done on value creation one time (one place and as soon as possible)
Very cooool language
Congrats!!!
Beta Was this translation helpful? Give feedback.
All reactions