Posts tagged "Bosque"

Microsoft's Bosque

Microsoft Releases Bosque Programming Language

April 17, 2019 Posted by News 0 thoughts on “Microsoft Releases Bosque Programming Language”

In a research paper written by Mark Marron and recently published by Microsoft, Marron introduces a new paradigm that involves “lifting the model for iterative processing away from low-level loop actions, enriching the language with algebraic data transformation operators, and further simplifying the problem of reasoning about program behavior by removing incidental ties to a particular computational substrate and indeterminate behaviors.” This new paradigm is termed regularized programming and is supposed to revolutionize software development in the same way structured programming and abstract data types did in the 70’s.

Marron claims that these improvements will come in the form of better “software quality, programmer productivity, and compilers/tooling.” The Bosque language is then used as an example of a programming language built with a raguarized model in mind, giving it the ability to “[eliminate] major sources of errors, [simplify] code understanding and modification, and [convert] many automated reasoning tasks over code into trivial propositions.”

 

What is Bosque?

Bosque is a combination of TypeScript in syntax and ML and JavaScript in semantics. In short, the language will be familiar to anyone who’s ever built a front end app. The language includes nominal types, structural types, and combination types.

function nsum ( d : I n t , . . . a r g s : L i s t [ I n t ] ) : I n t {
return a r g s . sum ( d e f a u l t =d ) ;
}
function np ( p1 : I n t , p2 : I n t ) : {x : I n t , y : I n t } {
return @{x=p1 , y=p2 } ;
}
/ / c a l l s with e x p l i c i t arguments
var x = nsum ( 0 , 1 , 2 , 3) ;
var a = np ( 1 , 2) ;
var b = np ( p2 =2 , 1) ; / / same as a
var c = np ( p2 =2 , p1 =1) ; / / a l s o same as a
/ / c a l l s with spread arguments
var t = @[1 , 2 , 3 ] ;
var y = nsum ( 0 , . . . t ) ; / / same as x
var r = @{p1 =1 , p2 =2};
var d = np ( . . . r ) ; / / same as a

 

What differentiates Bosque from JavaScript and its supersets is the fact that it provides “specialized bulk algebraic data operations and integrated support for none (or optional data) processing.”

Bulk Algebraic Data Operations

Marron gives examples of both bulk algebraic data operations and none processing. Here’s how he outlined what bulk algebraic data operations look like when used with Bosque:

 “The bulk algebraic operations in BOSQUE start with support for bulk reads and updates to data values. In addition to eliminating opportunities to forget or confuse a field the BOSQUE operators help focus the code on the overall intent, instead of being hidden in the individual steps, and allow a developer to perform algebraic reasoning on the data structure.”

 @[7 , 9]
(@[7 , 8 ] ) <~(0=5 , 3=1) ; / / @[5 , 8 , none , 1]
(@[7 , 8 ] ) <+(@[5]) ; / / @[7 , 8 , 5]
(@{ f =1 , g =2})@{f , h } ; / / @{f =1 , h=none }
(@{ f =1 , g =2}) <~( f =5 , h =1) ; / / @{f =5 , g =2 , h=1}
(@{ f =1 , g =2}) <+(@{ f =5 , h =1}) ; / / @{f =5 , g =2 , h=1}
Baz@identity ( 1 )@{f , h } ; / / @{f =1 , h=t ru e }
Baz@identity ( 1 )@{f , k } ; / / error
Baz@identity ( 1 ) <~( f =5) ; / / Baz@{f =5 , g =1 , h=t ru e }
Baz@identity ( 1 ) <~(p =5) ; / / error
Baz@identity ( 1 ) <+(@{ f =5}) ; / / Baz@{f =5 , g =1 ,

 

“None” Processing

In Bosque, none values are equivalent to null or undefined. Rather than following JavaScript’s truthy coalescing, Bosque uses both  “elvis operator support for all chainable actions and specific
none-coalescing. ”

@{}.h / / none
@{}.h . k / / error
@{}.h ? . k / / none
@{h = {}} . h ? . k / / none
@{h={k =3}}. h ? . k / / 3
f u n c t i o n d e f a u l t ( x ? : I n t , y ? : I n t ) : I n t {
return ( x ? | 0) + ( y ? | 0) ; / / d e f a u l t on none
}
d e f a u l t ( 1 , 1) / / 2
d e f a u l t ( 1 ) / / 1
d e f a u l t ( ) / / 0
f u n c t i o n check ( x ? : I n t , y ? : I n t ) : I n t ? {
return x ?& y ?& x + y ; / /

Atomic Constructors

The language also uses atomic constructors to regularize development. This is achieved by using  “direct field initialization to construct entity (object) values.”

concept Bar {
f i e l d f : I n t ;
f a c t o r y d e f a u l t ( ) : { f : I n t } {
return @{f =1};
}
}
e n t i t y Baz p r o v i d e s Bar {
f i e l d g : I n t ;
f i e l d h : Bool = t ru e ;

 

 

A Side By Side Comparison

It’s when JavaScript and Bosque are compared side to side that you can see what Marron means by stripping away “accidental complexity.” As a regularized programming language, Bosque aims for a declaritiveness and conciseness not found in JavaScript and other structured programming languages.

 

JavaScript vs Bosque

 

Conclusion

Bosque presents an interesting paradigm shift in a crowded field of programming languages. It will be worthwhile watching how the language matures as an ecosystem of tooling develops around it.  On their website, Microsoft has made the new programming language available to open source contributors under an MIT license. You can explore Bosque in Microsoft’s GitHub repo.

 

Please follow and like us:
0