Closed sirinath closed 3 months ago
Philosophy:
Try to find the exactly one method/library/structure to do the thing in one domain.
Some advices:
Add dag graph data structure for any language translation , any library analysis/refactory, try language synthesis in the same domain all in one library and in one syntax; strong/efficient tag system. use the previous library as many as possible. strong/efficient tag system.
May be we can find a recursion method for graph like data structure in language translation.
Try to use some NLP methods for language translation(such as word2vec or others).
Reference:
https://docs.shiftleft.io/ocular/cpgql/reference-card (see also SPARQL(knowledge base) and Graphdbs usage for language analysis and translation)
http://harmonia.cs.berkeley.edu/papers/twagner-glr.pdf
codeviz(inspire from graphviz)
codeql
https://tree-sitter.github.io/tree-sitter/
language reference: haskell(project semantic) ATS2 Oberon2 or Oberon7(Pascal like) HSV (Bluespec; for VLSI design, haskell like)
There's a lot to unpack here. But first of all, thank you for your enthusiastic interest in the future of Racket!
I think it would be easier to engage with these ideas if you separated out what necessarily has to be done in Rhombus from what can be done in libraries and frameworks. That would make it easier to prioritize. Additionally, have you looked through much of the existing discussions and issues? Some of the ideas in this issue may be related and it would be helpful to see where they fit in with the other conversations going on.
Wishlist for Meta Programming and Language-Oriented Programming
Wish List for General Purpose Programming Language
Language Domains
Language features
@
to denote nominative.Wishlist of Key Features
Exact syntax and mechanics how these features are to be implemented is yet to be determined. The syntax discussed here is suggestive and not concreate.
Minimum Key Words
The number of key words will be limited. E.g.
tp
- type or shorthand‘
,fn
- function,tm
- term which is optional for variable definition Scopes take the name of the object and function. Modules also can be mimicked by singleton objects.Evaluation Strategy
Evaluation strategy is lazy.
Nominative and Structural Types
Both nominative and structural types will be available. There will be:
E.g. In
tp @Person(@age: int, @name: str)
the@
symbol denotes nominative type. If there is no@
symbol,@Point(x: int, y: int)
, then lable is not used to type check as in the case ofx
andy
where anyint
can occupy the these element in type checking.If a nominative lable is present this is considered a subtype over a type without a nominative lable. E.g.
tp @A(@a: X) <: tp A(@a: X) <: tp A(a: X)
andtp @A(@a: X) <: tp @A(a: X) <: tp A(a: X)
whiletp A(a: X) = tp A(X) = (X)
as there is no nominative lable.Value Types
Value types would supported:
=
for assignment in absence of mutation effects.:=
and=:
for mutative assignment head and tail.~>
) and to-from (<~
) using relevant effects.Values are defined as
tm a: int = 1
ora: int = 1
by omitting optionaltm
. If mutation effects are presenta: int ::: MUT = 1
. The definitions follow the patterntp symbol-or-literal : types : scope :: refinement-predicates :.: values-ranges-and-state-trasitions :~: proxy :=: proof-checks :@: annotations
.Type Systems Operators
Following type operators would be available:
Holes, Anonymous Values and types
[_]
(and[_][0]
,[_][1]
,[_][2]
, …, in order if there are many) refers to anonymous or unnamed values and[?]
(and[?][0]
,[?][1]
,[?][2]
, …, in order if there are many) refers to and anonymous or unnamed types. Similarly[#]
refers to anonymous or unnamed symbols with[#][0]
,[#][1]
,[#][2]
if there many symbols.[->]
,[<-]
,[|->]
,[<-|]
,[=>]
,[<=]
,[|=>]
,[<=|]
and[<->]
(for invertible functions) can be used for anonymous and unnamed functions with[<-][0]
/[->][0]
/[<->][0]
/…,[<-][1]
/…,[<-][2]
/… referring if there are many. Similarly[<>]
refers to environment or scope which is anonymous or unnamed scopes can be referred as[<>][0]
,[<>][1]
, etc.[*]
can used to refer to anything which is anonymous or unnamed.[_][a <: X :: s"${a}".match("a*")]
refers to find values which is a subtype ofX
and starts with “a”.[?][A <: X :: s"${A}".match("A*")]
refers to find types which is a subtype ofX
and starts with “A”.[#][a :: s“${a}”.match("a*")]
refers to find symbols starting with “a”.[->][f: s“${a}”.match("a*")]
refers to a functions starting with “a”.Symbols
Symbols are defined using
sm
or#
.Following
a :: s"${#}".match("get*") := getX()
ensuresa
can only be assigned from a variable or function starting with “get”.Function
Functions are defined with
fn
taking 1 tuple or function and retuning a tuple or another function. A function can also have a context. Perhaps a function could be defined as in the following examples:fn f: (ctx: X |=> a: A -> (io = (x)? (x > 0): io |? (), mem = mem) -> ()) {...}
whereIO
an effect is present givenx > 0
,fn f: a: A -> b: B {...}; fn f^: a: A <- b: B {...}
orfn f^: b: B -> a: A {...}
where inverse functions is also defined. If the inverse is algebraically solvable and invertible then the following can be used where the compiler derives the inversefn f: a: A <-> b: B {...}
.|->
or<-|
can be methods and extension methods. Method can be part of many objects(a: A :+: b: B) |-> ...
or operate on many objects, e.g.,(a: A, b: B) |=> ...
with usage as(a, b).f
ora: A |-> b: B |-> ...
with usage asb.(a.f)
or(a, b).f
. If|=>
or<=|
is used the parameters are passed implicitly.The parameters can be values, variables, types, functions, effects. Type parameters are defined as
A =>
or<= A
. In caseA
is of a specific typeA: X => ...
or... <= A: X
whereX
is a type.Functions can be defined on values, e.g.,
fn f: (0..9 -> 10..19) :|: (20..29 -> 30..39)
. If invertiblefn f: (0..9 <-> 10..19) :|: (20..29 -> 30..39)
.As functions can be deduced by the presence of the arrows
fn
omitted if desired.When a function is passed into a function then the execution environment will become also available unless limited by access control.
Types
Types are can be define as
tm @A(a: X)
or‘@A(a: X)
. Types can be part of the tuple, e.g.,tp A(tp X)
ortp A('X)
or‘A('X)
.Tuples
Tuples can have nominative labelling, e.g.,
tp A(b: B, c: C)
. So can the fields, e.g.,tp @A(@b: B, @c: C)
. Nominative labelling can be mixed, e.g.,tp @A(b: B, @c: C)
ortp A(@b: B, c: C)
.Also membership can be depend on a value
tp A(b: B, (x)? (x > 0): c: C |? (_): ())
.Unions
Union can be both tagged and untagged. Untagged union and tagged union uses
:|:
and:+:
, e.g.,tp A(X :|: Y)
.tp A(x: X :+: y: Y)
,tp A(@x: X :+: y: Y)
,tp @A(x: X :+: y: Y)
.The participation can be conditional on a value, e.g.,
tp A(x: X :+: (z)? (z > 0): y: Y |? (_): ())
, or type.Intersection
Intersection types can be both tagged and untagged and uses
:&:
and:*:
. Participation can conditional on a value or type.Conditional Types
Types can be defined using pattern matching. E.g.
tp a: (z)? (z > 0): X |? (_): Y
Range Types
Data ranges are represented as types.
Annotations / Tags
Annotations are regular type of values which are associated with other types of values. Annotation are accessible to the meta programming facility which does the annotation processing.
Companion Objects
Companion objects can be implemented defining a singleton object, e.g.,
vr A(a: int)
. This similar to type definition but usingvr
instead oftp
.Effects
Effect definition will have the same definition syntax with as types and variables to reduce syntactical complexity. Effect can be conditional and dependently typed. They can be also 1st class and parameterised so that different effect handlers can be swapped, e.g., changing allocators. If viable effects may use the same syntax used to define singleton object.
Fine Grain Access Modifiers
Access modifier are not baked into the language but can be language defined. Using attributes fine grain access modifiers can be implemented. E.g.
a :@: (x)? (true): read(allow = q"<: A :&: B") |? (false): read(allow = q"<: X :&: Y")
any subtype ofA :&: B
can reada
but not otherwise whenx
is true and any subtype ofZ :&: Y
can reada
whenx
is false. The checking mechanism will prove that any usage is completely sound.Modules and Packages
Packages and modules can use the same syntax to define singleton objects.
Expressions
Expressions evaluate to values or types and can be conditional on other types or values. Similarly function.
AOP Through Effects
AOP programming will be facilitated through the effect system.
Control Flow
Control flow is achieved through effects, but mimic
for
for fixed number of iteration,while
for precondition based iteration,do while
for postcondition based iteration, in the case of loops andif
conditional statements. Control flow can be defined as effects and syntax can be enhanced through macros.Other Control Mechanisms
Fist call continuations, generators, coroutines, exception will be supported through the effect system.
Memory Allocation
Memory allocation is also done through the effect system. Different allocators and allocation schemes can be defined the users also.
Based on the allocator used first class heaps and region based memory allocation schemes would be available.
The allocators as well as the whole system should ideally be implemented in the language itself without the need of any low level or foreign language code. Also the code should be deemed as safe code.
Threading and Parallelism
Parallel primitives and patterns as well as algorithmic skeleton with nesting and composition are defined through the effect system at the library level. The users can add additional items.
Similarly constructs to implement process calculi and algebras, cancel and error propagations, supervision structures can be provided and the users can extend them and also provide their own.
The transfer of the variable bindings to different scopes and access control also can should be modellable.
IO and FFI
IO and FFI calls are achieved through effect system. Any IO or FFI cannot be unsafe hence all exceptional situations much be handled and should not break the guarantees of the language and type system.
Typed State, Enforced States and State Transitions
Initial state and state transitions can be enforced, e.g.,
a :.: (1, 2, 3) -> (4, 5, 6) <-> (7, 8. 9), (4, 5, 6) -> (10, 11, 12)
. The transitions can be,
or|
or&
separated, e.g.,p: Point :.: (0, 0) -> (1, 0) | (0, 1) & p.x != p.y
.Also subtyping can be conditional or state dependent.
Syntactic Macros, Syntax Extension and Operators
Syntax to a certain level will be extensible. This also can be used to have custom operators with flexible associativity and precedence.
Sub and Super Typing
The type system can be very flexible where sub and sub types can be defined, e.g.,
tp A <: B
define thatA
is a super type ofB
, similarlytp A :> B
define thatA
is a super type ofB
. If a type cannot have a super type this can be enforced by quoted expressions (tp A :: q"$super(A)" == ()
) or type queries (tp A :: [?][? :> A] == ()
).To have consistent memory layout the right most elements are placed before the elements in the left by default. Alternatively
tp A :> B (B..., a: int)
can be used to specify the layout.Arrays
Arrays can be defined as
[(int, int) -> int][3, 5]
. Infinite sequencesFirst-class Code and Expressions
Code and expressions are 1st class. Also language is homoiconic. Code can be generated, manipulated and transformed like any other data structure.