Skip to content

Language features needed for Project Euler coverage: bigint, hash maps, if-expressions, and C error visibility #252

Closed

Description

@godofecht

Context

We are solving Project Euler problems in Flow (https://github.com/godofecht/flow-euler). 766 problems are solved. The remaining 22 are blocked by a small set of missing language features. Below is a breakdown of what is needed and why.

1. Big integer support (bigint type)

Blocks: p641, p646, p685, p698, p608 (at least 5 problems)

Many Euler problems require integers beyond i64 (max ~9.2e18). Examples:

  • p641: N=10^36, needs Mertens function with memoization on values up to 10^18
  • p685: binomial coefficients C(100000, 50000) far exceed i64
  • p698: large combinatorial sums
  • p608: Dirichlet series with intermediate products exceeding i64

Currently we work around this with i128 where possible, or skip the problem. A built-in bigint type with +, -, *, /, %, comparison operators, and mod_pow would unlock these directly.

2. Built-in hash map / dict

Blocks: p699, p678, p696 (at least 3 problems, and makes many others easier)

We currently hand-roll open-addressing hash tables using calloc and manual probing. This is verbose, error-prone, and hard to tune. A built-in map[K, V] or set[T] type with insert, contains, get, remove would:

  • Make p699 (DFS with visited set + factorization cache) straightforward instead of 200+ lines of boilerplate
  • Make p678 (perfect powers enumeration with multiplicity map) feasible
  • Make p696 (NFA/DFA state tracking) cleaner

3. if expressions

Blocks: No problems directly, but causes friction in every port

Flow does not support if as an expression. Every conditional value requires:

let result: i64
if cond {
    result = a
} else {
    result = b
}

instead of:

let result: i64 = if cond { a } else { b }

This bloats code significantly in numerical ports where ternary logic is common.

4. Floating-point and math functions

Blocks: p620 (at least 1 problem)

p620 needs pi, acos, and basic float arithmetic for gear angle computations. Flow currently has no floating-point type. A f64 type with standard math functions (sqrt, sin, cos, acos, pi constant) would unlock this.

5. flow run swallows C compilation errors

Blocks: Debugging all problems

Both the flowc host (line 125 of flow) and the python host (line 517) redirect C compiler stderr to /dev/null:

if ! clang ... 2>/dev/null; then
    print_error "C compilation/linking failed"

When compilation fails, the user sees only "C compilation/linking failed" with no indication of what went wrong. This makes debugging generated C code extremely painful. Suggest either:

  • Print the stderr on failure (before the error message), or
  • Add a FLOW_VERBOSE=1 env var that disables the 2>/dev/null

Summary

Feature Problems unlocked Impact
bigint type 5+ high
hash map / dict 3+ high
if expressions 0 (ergonomics) medium
f64 + math functions 1 low
C error visibility 0 (debugging) high

The first two (bigint, hash maps) would close most of the remaining gap. The C error visibility fix is a one-line change that would immediately improve the development experience.

Activity

  1. godofecht commented on Aug 10, 2026

    @godofecht
    ContributorAuthor

    All three features are implemented: bigint (lib/stdlib/bigint.flow with add/sub/mul/mod), hash maps (lib/stdlib/collections.flow with HashMap_i64_i64), and if-expressions (let x = if cond { a } else { b }). Tests pass in tests/unit/test_misra_euler_batch.py for hashmap and bigint smoke tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions