← 返回日报
略读 预计 1 分钟

Show HN: Fuse – statically typed functional programming language

摘要

Fuse 是一门静态类型、纯函数式编程语言,基于 System F 类型系统,支持高阶多态、代数数据类型、泛型和 trait,采用双向类型推断,语法借鉴 Rust、Python、Scala 和 Haskell。它编译到 GRIN 全程序优化器,再通过 LLVM 生成原生二进制,声称零成本抽象。当前支持 Linux x86_64 和 macOS ARM64,提供一键安装脚本。

荐读理由

Fuse 展示了将 System F 类型系统、GRIN 优化器和 LLVM 后端结合的完整工具链,其架构思路(如双向类型推断、trait 机制)可迁移到自研语言或编译器中,但正文未提供实际性能数据或应用案例,直接采用风险较高。

原文

Fuse

fuse

Fuse is a statically typed, purely functional language with higher-kinded types and ad-hoc polymorphism. It compiles to the GRIN whole-program optimizer, producing LLVM-generated native code.

Overview Get Started

trait Functor[A]:
    fun map[B](self, f: A -> B) -> Self[B];

impl List[A]:
    fun fold[A, B](l: List[A], z: B, f: (B, A) -> B) -> B
        match l:
            Cons(h, t) => List::fold(t, f(z, h), f)
            Nil => z

    fun sum(l: List[i32]) -> i32
        List::fold(l, 0, (a, b) => a + b)

impl Functor[A] for List[A]:
    fun map[B](self, f: A -> B) -> List[B]
        List::fold(self, Nil[B], (t, h) => Cons(f(h), t))

fun fmap[A, B, F: Functor](f: A -> B, x: F[A]) -> F[B]
    x.map(f)

fun main() -> IO[Unit]
    let l = Cons(1, Cons(2, Cons(3, Nil)))
    let l2 = fmap(x => x * 2, l)
    print(int_to_str(List::sum(l2)))

Features

Statically typed

Type system based on System F with higher-order polymorphism. Algebraic data types, generics, and traits give you powerful tools to model your domain.

Purely functional

Every function in Fuse is a pure function. Pattern matching, higher-order functions, and do notation let you write expressive, composable code.

Type inference

Bidirectional type checking with support for higher-order types. Only function type signatures are required, for readability and verbosity. Everything else is inferred.

Clean syntax

Drawing inspiration from Rust, Python, Scala, and Haskell to bring a readable syntax to purely functional programming. Indentation-based blocks, lambda expressions, and ML-like syntax keep code clean and approachable.

Compiles to GRIN

Whole-program optimization through GRIN and code generation via LLVM produces fast, small native binaries with zero-cost abstractions.

Install Fuse

Get the Fuse toolchain on Linux (x86_64) or macOS (ARM64).

curl -fsSL https://fuselang.github.io/fuse/fuseup | sh

Hacker News · 项目/工具 · 101 赞 · 29 评 讨论 → 阅读原文 →

这条对你有帮助吗?