WARNING: Visionary/ Feeling inspired. Call for advice, suggestions on how to proceed.
Summary
I imagine to be able to declare only the type of a variable and not assign it any value. This might be useful as It can act as typed hole
, a placeholder of sorts, that still would allow some forms of type checking, code generation, pattern matching, meta programming, linting, syntax highlighting, IDE support etc.
TL;DR Given some type
T
, I want to be able to dox = @var(T)
inside some limited context/ scope where it maybe useful to let it behave as ifx
were a term of typeT
.
EDIT: The above has been partially solved here. Opens discussions to other things below:
Intention for Useage
These are some ways I imagine wanting to use this:
- For incremental coding (inspired by Hazel):
@unfinished_code begin
x=@var(T) where Int<:T<:Real
y=x+2
end
- Using Julia natively as a query language:
I am aware that there are Julia ORMs. But to be able to express the constraints/ pattern of a query in Julia natively might open unexpected applications (as, database need not be the only target for such a query: for example Trustfall).
I am imagining something like these:
pattern = @search_pattern begin
s = @var(student)
1 <= s.studentID <= 5 || s.studentID = 5 || occursin(r'%Maximo', s.FullName)
s.sat_score > 1400 || s.sat_score < 1000
end
results = source.match(pattern)
instead of:
select studentID, FullName, sat_score, recordUpdated
from student
where
(
studentID between 1 and 5
or studentID = 8
or FullName like '%Maximo%'
)
and sat_score NOT in (1000, 1400);
in sql
, or maybe something like this:
search_pattern = @pattern begin
(r, tom, m) = @var(T, Person, Movie) where T<:relationship
tom.name = 'Tom Hanks'
r = T(tom,m)
end
results = source.match(search_pattern).collect(typeof(r), m.title)
instead of:
MATCH (tom:Person {name:'Tom Hanks'})-[r]->(m:Movie)
RETURN type(r) AS type, m.title AS movie
in cypher
in Neo4j
, or
search_pattern = @pattern begin
u, obj, act = @var(user, object, action)
u.name='Kevin Morrison'
obj.path='path'
act.name = 'modify_file'
permission(u,access(obj,act))
end
results = source.match(search_pattern).collect(obj.path)
instead of:
match
$user isa user, has full-name 'Kevin Morrison';
($user, $access) isa permission;
$obj isa object, has path $path;
$access($obj, $act) isa access;
$act isa action, has name 'modify_file';
fetch $path;
in typeql
from typedb
.
Conclusion
Yes, this is asking for a lot of syntactic sugar. And I don’t know if this is even possible. But I hope to open a discussion towards the right kind of syntactic sugar that is useful and possible.