Comments (2)
Bosque is statically typed, with records, tuples, objects, union, and (limited) intersection types.
In Bosque the open record type {...}
is a record with some number of properties with unknown names. We allow type checks and casts with the syntax:
function foo(arg: {...}): {f:Int, g:Int} | {f:String, g:Bool} | None {
//check if arg is of type {f:Int, g:Int}
if(arg->is[{f:Int, g:Int}](arg)) {
return arg->as[{f:Int, g:Int}](); //cast to type
}
return arg->tryAs[{f:String, g:Bool}](); //try cast or return None if it fails
}
Currently we don't have a nice JSON interop story and I would like to do something here. From your comment I assume you are thinking something like:
function foo(data: String): {f: Int, g: Int} {
var check = JSON::is[{f: Int, g: Int}](data); //check if string is JSON format that is convertable to record type
if(check) {
return JSON::parse[{f: Int, g: Int}](data); //parse the json string as the given record type
}
else {
return none;
}
from bosquelanguage.
I suppose, though that looks pretty verbose. I'd rather just JSON::parse[{f: Int, g: Int}](data)
throw an error/return an optional. If Bosque ever had an interop story with TypeScript or JS modules, the general case of converting an any
or unknown
type to a stronger type would be much more beneficial--I can't remember the last time I called JSON.parse
directly.
from bosquelanguage.
Related Issues (20)
- Debug vs Release time checks HOT 1
- Can't get conjunction type resolution to work HOT 1
- Parser ambiguity on "("
- Concept & and provides
- SymTest does not allow a List to be mapped into another type HOT 2
- Postcondition `ensures` does not compile when ref parameter provided HOT 1
- Could the built-in test runner be used to write unit tests for user programs? HOT 7
- IR-only code-gen backend? HOT 1
- It would be very-very nice if you could cite our paper :)
- Modelling remote execution and storage within Bosque
- npm ERR! Test failed BosqueLanguage-LearnBosqueProgramming branch HOT 1
- This repo is missing important files HOT 2
- Model constraints for CADL HOT 1
- SMT Division
- BigX support
- Decimal Support
- Rational Support
- ASCIIString
- Design of arithmetic operations (static vs. dynamic)
- Enum values
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 bosquelanguage.