Comments (5)
This is the problematic elaboration which causes the exception. I also tried disabling fixed point elaboration to make sure it wasn't fixed point casting related, ie it still occurs given this elaboration:
from hazel.
Here's my analysis of what's going on. First, three similar but ultimately unproblematic scenarios for context, followed by the one above:
SCENARIO 1: if there's no annotation on the fn, but an annotation on the arg b:
let f = fun b:? {b[?->Bool] && true} in f(true[Bool->?])
=> (fun b:? {b[?->Bool] && true})(true[Bool->?])
=> (true[Bool->?])[?->Bool] && true
=> true[Bool->Bool] && true
=> true && true
=> true
SCENARIO 2: if there is an ? -> ? annotation on the fn, and an annotation on the arg b:
let f:?->? = fun b:? {(b[?->Bool] && true)[Bool->?]} in f(true[Bool->?])
=> (fun b:? {(b[?->Bool] && true)[Bool->?]})(true[Bool->?])
=> ((true[Bool->?])[?->Bool] && true)[Bool->?]
=> (true[Bool->Bool] && true)[Bool->?]
=> (true && true)[Bool->?]
=> true[Bool->?]
=> true
SCENARIO 3: if there is an Bool -> ? annotation on the fn, but no annotation on the arg b:
let f:Bool->? = fun b: Bool {(b && true)[Bool->?]} in f(true)
=> (fun b: Bool {(b && true)[Bool->?]})(true)
=> (true && true)[Bool->?]
=> true[Bool->?]
=> true
SCENARIO 4 (PROBLEM): if there is an Bool -> ? annotation on the fn AND an:
let f:Bool->? = fun b: Bool {(b[?->Bool] && true)[Bool->?]} in f(true)
=> (fun b: Bool {(b[?->Bool] && true)[Bool->?]})(true)
=> (true[?->Bool] && true)[Bool->?]
=> CastBVHoleGround
The inconsistency arises because the cast on the use of the parameter 'b' is determined by the annotation on the function parameter, but the cast on the function argument is determined by the annotation on the function. Thus in the case where these annotations are consistent, but the parameter annotation is less specific than the function annotation, we are left with an unresolved cast from a Hole to a Ground type.
Not obvious to me how to resolve this...
from hazel.
One way would be to change the statics of type annotations and say that in analytic mode, the pattern of an annotation should be analytic against the joint type of the analytic type and the annotation type (if consistent). that addresses the immediate issue but seems to trigger other casting exceptions in other code (can't really be specific without more work to minimize them)
from hazel.
@cyrus so the change we discussed isn't working because in the above scenario (4), the self-type of the function literal "fun b:? -> b && true" is Bool->Bool. So the function literal just gets cast from Bool->Bool to Bool->?, so after distribution the argument just gets cast Bool->Bool i.e. no-op.
The reason the self-type of the function literal "fun b:? -> b && true" is Bool->Bool is because the self-type of composite things are generally based on the fixed types of their components. So in this case, because the function literal is in analytic against Bool->?, the pattern ends up in analytic against Bool, so although the pattern has a self-type of ?, its fixed type is Bool.
Not quite sure how to proceed here...
from hazel.
I guess i could special-case the casting for function literals to use the self-type of the pattern + body instead of the self-type of the function literal, but not sure what the principle is exactly
from hazel.
Related Issues (20)
- Linter
- Integrate live values into editor UI
- Code tour support
- Convert some Project Euler problems into Hazel exercises
- Line numbering
- Variable renaming UI
- Structured search
- Drag-and-drop blocks editing UI for Hazel
- cannot delete `=` when let type annotation trails with a hole HOT 1
- 1 @ 2 doesn't throw an error HOT 2
- Fixpoints in SynFun position create static errors HOT 2
- Structural copy/paste
- Relative precedence of ; and && HOT 1
- Add ability to decide on stepping strategy during stepping
- Think about how to update the stepper state when elaboration changes
- Make undo return you to previous stepper state HOT 1
- Constructors that require arguments shouldn't be in patterns without arguments HOT 4
- case checker on recursive types
- ADTs with hole type consistency have casting bug HOT 1
- ListLit of different Construtor type does not raise type error HOT 1
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 hazel.