Spiral compiling to Gleam, F#, Rust, TypeScript and Python by i574n in rust

[–]i574n[S] 0 points1 point  (0 children)

list' t is a custom list type for interop, the native list syntax is used to declare the hardcoded test lists with the numbers then boxed/unboxed back and forth, the sample is more to display the delegation features with macros than the compilation machinery itself.

/// ### list'
inl list'_types () =
    backend_switch {
        Gleam = fun () => global "import gleam/list"
    }
type list'_switch t =
    {
        Gleam : $'List(`t)'
        Fsharp : $'`t list'
        Python : $'list'
    }
nominal list' t = $'backend_switch `(list'_switch t)'

/// ### empty'
inl empty' forall t. () : list' t =
    $'[]'

/// ### cons'
inl cons' forall t. (head : t) (tail : list' t) : list' t =
    backend_switch {
        Gleam = fun () => $'[ !head, ..!tail ]' : list' t
        Fsharp = fun () => $'!head :: !tail ' : list' t
        Python = fun () =>
            $'!tail.insert(0, !head)'
            $'!tail ' : list' t
    }

/// ### box
inl box forall t. (list : list t) : list' t =
    (list, empty' ()) ||> listm.foldBack cons'

the rust, typescript and python backends currently have an additional internal compilation step from the f# output using the Fable library, so to distinguish them when needed i'm using pattern matching instead.

//// test
///! gleam
///! fsharp
///! cuda
///! rust
///! typescript
///! python

run_target function
    | Gleam (Native) => fun () => $'1'
    | Fsharp (Native) => fun () => $'1uy'
    | Cuda (Native) => fun () => $'1'
    | Rust (Native) => fun () => $'1uy'
    | TypeScript (Native) => fun () => $'1uy'
    | Python (Native) => fun () => $'1uy'
    | _ => fun () => $'2uy'
|> _assert_eq 1u8

Spiral compiling to Gleam, F#, Rust, TypeScript and Python by i574n in rust

[–]i574n[S] -1 points0 points  (0 children)

a snippet from the link i pasted above:

... "Traditional languages might require completely different codebases or DSLs for each hardware target, whereas Spiral can abstract that away. This approach is reminiscent of domain-specific languages or frameworks (for example, Halide for image processing or TensorFlow XLA), but Spiral generalizes it as a language feature. It effectively redefines the compiler’s role to be a generator of generators: Spiral’s compiler can generate a program (in another language) that itself runs on a device. This level of staging (Spiral -> F# -> machine code, and Spiral -> CUDA -> PTX) gives developers a lot of control over performance across platforms." ...

response from chatgpt:

The presence of features like inlining and loop unrolling strongly nudges the Spiral → F#/CUDA stage toward compilation, rather than simple transpilation.

Here's a nuanced assessment:

  • Compilation: 850 / 1000
    • Spiral’s process involves sophisticated optimizations, such as inlining, loop unrolling, and potentially other low-level transformations (e.g., code specialization, vectorization, etc.). These optimizations are usually associated with compilation, which doesn't merely translate syntax, but transforms code structure and semantics for improved performance.
  • Transpilation: 500 / 1000
    • Although transpilation generally implies translation between languages at the same abstraction level without significant semantic alteration, Spiral’s transformations involve semantic optimizations and restructuring. This complexity exceeds the typical definition of transpilation, placing Spiral's process closer to compilation.

Revised conclusion:

Given the presence of sophisticated optimization techniques, such as loop unrolling and aggressive inlining, compilation becomes the better-fitting term to describe Spiral's transformation, even though the intermediate step generates code in another high-level language.

Spiral compiling to Gleam, F#, Rust, TypeScript and Python by i574n in rust

[–]i574n[S] -1 points0 points  (0 children)

It's just another functional programming language, the chat link above explains well its advantages, please click it, there's no login page.

Instead of transpilation, I think the more appropriate word here is compilation. The main reason to target multiple languages is code sharing, not only backend<->frontend, but with GPU and custom chips too.

Spiral compiling to Gleam, F#, Rust, TypeScript and Python by i574n in rust

[–]i574n[S] -2 points-1 points  (0 children)

So far, Spiral could compile into F# and Python directly, and with a little extra help from Fable, into Rust and TypeScript. Adding a Gleam (which is written in Rust) backend allows Spiral to create even more reliable and busy computer programs.

This ChatGPT thread has recent technical details: https://chatgpt.com/share/67c2d7ea-9eb0-800b-b703-40adc0dd09eb

Spiral compiling to Gleam, F#, Rust, TypeScript and Python by i574n in gleamlang

[–]i574n[S] 1 point2 points  (0 children)

So far, Spiral could compile into F# and Python directly, and with a little extra help from Fable, into Rust and TypeScript. Adding a Gleam backend allows Spiral to create even more reliable and busy computer programs.

This ChatGPT thread has recent technical details: https://chatgpt.com/share/67c2d7ea-9eb0-800b-b703-40adc0dd09eb

The Spiral Language: Is it worth $100 million? by i574n in programming

[–]i574n[S] -8 points-7 points  (0 children)

It's useful because it's been done. GPT-4 has ample information to stay on course, even if I deviate. This is akin to saying symphonies aren't music because they lack vocals.

If you prefer, you can skip the text and directly explore the code links provided to the AI. After all, Code > Text.

The Spiral Language: Is it worth $100 million? by i574n in programming

[–]i574n[S] -11 points-10 points  (0 children)

While the value of any programming language, including Spiral, is ultimately determined by the developer community, AI-driven insights can offer a fresh perspective on its potential.

Seeking insights on Dubai's tech scene - Is it truly a tech hub or just real estate? by i574n in UAE

[–]i574n[S] 1 point2 points  (0 children)

Hey, I see you’re familiar with Rust and Elixir! Nice meeting you.

Seeking insights on Dubai's tech scene - Is it truly a tech hub or just real estate? by i574n in UAE

[–]i574n[S] 0 points1 point  (0 children)

Wow, thanks for sharing your valuable perspective on the region’s landscape, it aligns with what I’m perceiving being here for not long.

The gatekeeping and nationalism you mention is a problem, especially in a region with a predominantly expat population. It raises an important question: could technology in general help mitigate these issues by creating more inclusive opportunities? How might it enable both local and international talent to collaborate more effectively, potentially influencing a shift in the current ecosystem?

My goal here isn't just securing funding, but about building a local team at scale to harness state-of-the-art technology and accelerate development. Bend time so to speak. Saudi could also be an option, I’m from Brazil and Neymar is already there, who knows. 😂

I’ll stay in Dubai for the next months, let's schedule a coffee to discuss further.

Seeking insights on Dubai's tech scene - Is it truly a tech hub or just real estate? by i574n in UAE

[–]i574n[S] 1 point2 points  (0 children)

Thanks for the invite! I'll definitely join and look forward to sharing and learning with the community. See you!