Comments (1)
I implemented a static type checker with physical dimensions acting as types, but there is one big (and potentially fatal) problem: the exponentiation operator. If we want to generally support
expr1 ^ expr2
then the type of that compound expression relies on the value of expr2
. It's not enough to statically compute the type/dimension of expr2
(which needs to be unity), we also need the value because
T[expr1 ^ expr2] =
if T[expr2] == 1:
T[expr1] ^ expr2
else:
TypeCheckError
This does not just force us to evaluate expr2
at compile time (type-check time), it forces us to evaluate everything at compile time, because expr2
could reference anything.
What are possible solutions to this?
-
Limited syntax in exponents
We could strictly limit the syntax ofexpr2
. For example: only allow integer exponents, nothing else. Or we could allow for simple computations likeexpr1^(2 * 3 + 4)
. That would be a real shame because we certainly want to support things likee^(-x^2/sigma^2)
somehow. -
Distinguish between integer/rational exponents and decimals
We could dispatch exponentiation with non-integer (non-rational?) exponents to a builtinpowf(expr1, expr2)
function that would only allow scalars as its first argument (and second). This way, we would always know the return type (also scalar):powf(expr1: Scalar, expr2: Scalar) -> Scalar
In addition, exponentiation with integer exponents would be type checked as above, i.e. we would still allow things like
v^2
or possibly evenarea^(1/2)
. Butarea^0.5
would not be possible anymore (unless we immediately transform that 0.5 literal to a rational).
Example:
T[0.5 * m * v^2] = T[m] * T[v^2] = T[m] * T[v]^2 = Mass * Speed^2 = Energy
from numbat.
Related Issues (20)
- Suggest correct casing if the entered unit doesn't exist HOT 3
- Add info for functions HOT 1
- Binary operations with callables
- Conversion of rotational speeds is not correct HOT 1
- Feature request: Option to disable color HOT 3
- Type system extensions HOT 1
- Add glibc (libc6) as dependency to debian package HOT 2
- New dimensions HOT 2
- Typed holes
- Currency Providers HOT 4
- Add lowercase aliases for currencies? HOT 2
- Add support for raw strings HOT 4
- layout shifts after terminal loads HOT 1
- Type inference: follow-up tasks
- Lists are embarrassingly slow HOT 5
- Give `quadratic_equation` a `List<B/A>` return type.
- Generic structs HOT 4
- Example from the syntax overview fails in 1.12.0 HOT 3
- `numbat-wasm/www/` has formatting issues HOT 1
- Struct field access fails if expression type is not yet concrete HOT 4
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 numbat.