3 ms·
I've recently arrived at a mixed declaration, which "distributes the information" across the line, I think in a way which allows it to grow without being overhw
by mjburgess 3y ago
I've recently arrived at a mixed declaration, which "distributes the information" across the line, I think in a way which allows it to grow without being overhwelming, (which i take to be a holy grail...)
fn calc :: (x: int) => x
fn calc :: tidy (x: str)
open(str).read()
fn calc :: tidy heap (x: int)
let data: api many(int) = new array.fill(x)(x)
repeat d <- data
print(d)
fn compiletime($i, $T) :: temp (xs: $T*$i)
let data: api many(int) = new array.from(xs)
let sum = xs.reduce(op(+))
sum
fn lotsofparam($i, $T) :: pure (
num: f32,
xs: $T*$i,
ys: api many(str),
zs: api numeric
)
let sum = xs.reduce(op(+))
return sum
- Filligree 3y agoCould you explain the annotations? I feel like there might be something interesting here, but I can’t read your notation.
- mjburgess 3y ago`tidy` is similar to python context managers, or an automatic `defer`. So any resources within the function have their `.close`s run. `heap` is a semantics of `new`: allocate to the global heap `temp` likewise means allocate to a smaller temporary arena `pure` means no allocations and no resources $vars are compile-time where $lowercase are integers, $UPPERCASE are types. The type int*10 is a static array, so $T*$i is a compile-time variable but run-time static array. The `api` keyword is for interface types, it's a syntax transform to a compile-time variable, ie., `fn($T) generic(x: $T)` with a compile-time constraint on $T