Comments (11)
I would go further tho and consider the bottom type to have implemented all traits. If we are adding a false type then we better make it as false as possible :)
from wright-lang.
Should if
also accept single expressions? i.e.
if expr1
expr2
from wright-lang.
What would the type of that expression be?
from wright-lang.
I would assume the type would be the least upper bound of all the branches, with short if
s being treated as having an implicit else <unit-type>
.
from wright-lang.
@alfriadox and I brainstormed result types for if expressions and suggested a disjoint union result type if the then and else branches have different types.
from wright-lang.
We could also do it the rust way and require that both branches be the same type.
from wright-lang.
Yeah I'm leaning towards the rust way. We would need to do some special stuff though, like rust, to make
if (val) {return a}
else {return b}
and
if (val) {return a}
return b
act the same
from wright-lang.
I think we need to think about returns as sorta a special case. They aren't exactly expressions and they should be able to choose what scope they return from.
from wright-lang.
https://doc.rust-lang.org/std/primitive.never.html
from wright-lang.
Yep, I agree that return
expressions should be the bottom type. With regards to parsing, since conditionals are expressions, we can write
return if val { a } else { b }
instead of using two separate returns
from wright-lang.
Anything that returns void can be just if cond {block}
and not require the empty else block. I am looking at the rust grammar right now and I thing we should follow that as closely as possible.
from wright-lang.
Related Issues (20)
- Multiline comments HOT 4
- Type System HOT 1
- Declassify underscore as an expression HOT 2
- AstEq trait HOT 2
- `self` expression
- Function Call Expression HOT 1
- Targets HOT 4
- Scoped Name/Identifier
- Class Definition Parser
- Struct Definition Parser
- Enum Definition Parser
- Union Definition Parse
- Type Definition Parser
- Trait Definition Parser
- Impl Block Parser
- Function Definition Parser
- Match Expression Parser
- If let expression parser
- Replace `# Comment` style with `// Comment` style.
- WebAssembly HOT 2
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 wright-lang.