Comments (3)
I still think this might be extra, I do this to enforce type checking.
type Platform = int;
const (
Unknown = Platform(0)
Linux = Platform(1)
Windows = Platform(2)
MacOs = Platform(3)
Web = Platform(4)
)
fn foo(p: Platform) {}
fn main() {
foo(Linux) // OK
foo(th.white) // Error
}
The only difference here is that the enum isn't finite, so anyone can construct it, however it can be prevented if the type is private and all in one module.
from umka-lang.
@skejeton I get no error in this case:
type Color = int
const (
white* = Color(255)
)
type Platform = int
const (
Unknown* = Platform(0)
Linux* = Platform(1)
Windows* = Platform(2)
MacOs* = Platform(3)
Web* = Platform(4)
)
fn foo(p: Platform) {
printf("%v\n", p)
}
fn main() {
foo(Linux) // 1
foo(white) // 255
}
from umka-lang.
Huh that's strange, I almost swear I checked that, since I used it in my now deleted UI rewrite: https://github.com/skejeton/save-game/blob/89a80cda6ef77c0ac87f45d582b9034b6d233b55/src/d_ui.um#L91
Maybe it's a good idea to make the type conversions strict?
from umka-lang.
Related Issues (20)
- Revise `std.um`
- `std.freadall` encounters a premature EOF error when reading files without "b" flag. HOT 3
- intercepting `std.exitif`
- Memory leak caused by a wrong optimization HOT 1
- `%v` format specifier enhancements
- `std.exitif()` truncates stack traces at 256 characters
- `[]` instead of `[]T` in error messages in `printf()` HOT 1
- Separate namespace for modules
- Cannot declare a forward type with the same name as an imported module
- Casting null to a weak pointer
- Allow dereferencing weak pointers
- No error on dereferencing null weak pointer HOT 2
- Memory usage statistics
- `a == b` is not equivalent to `b == a`
- Proposal: Anonymous struct embedding with method inheritance
- Umka API requires `main()` function in the main module.
- Optimize zeroing HOT 1
- No `libumka_static.a` in the Linux release folder
- Confusing error messages in type declarations HOT 1
- `append` stops after the first two appends on an empty dynarr HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from umka-lang.