Grain Programming Language

website·Indexed 34 days ago

https://grain-lang.org/docs

A language targeting WebAssembly with a comprehensive standard library. Documentation covers core types (BigInt, String, Array, Map, Set), WASI integration for filesystem and process management, and version releases from v0.3.0 Barley to v0.7 Farro.

Tokens
65.5K
Snippets
750
Records
809
Agent score
71%

What's inside Grain

  1. Overview of Grain Set

    A Set in Grain is an unordered collection of unique values. Operations on a Set mutate its internal state, meaning the set does not need to be re-assigned after modification. For an immutable version, use the Immutable submodule.
    from "set" include Set
  2. Overview of the Char type

    The Char type in Grain represents a single Unicode scalar value. It can be initialized using single quotes, such as 'a', '1', or '🌾'.
  3. Overview of the Pervasives module

    The Pervasives module acts as the global environment for Grain programs and is automatically imported into every program. While automatic, it can still be imported manually if needed.
    from "pervasives" include Pervasives
  4. Overview of Uint16 in Grain

    The Uint16 module provides utilities for working with 16-bit unsigned integers. In Grain, Uint16 literals are denoted with the uS suffix (e.g., 1uS, 10uS).
    from "uint16" include Uint16
    
    let x = 1uS
    let y = 10uS
  5. Overview of BigInt in Grain

    The BigInt type in Grain (introduced in version 0.5.0) provides arbitrary-precision integers. BigInt literals are denoted by the t suffix (e.g., 9223372036854775809t, 0t, -9223372036854775809t). To use BigInt utilities, include the module using from "bigint" include Bigint.
    from "bigint" include Bigint
    
    let myBigInt = 9223372036854775809t
  6. Overview of the WASI File module

    The wasi/file module provides low-level utilities for filesystem access and file manipulation within the WASI standard library. It is primarily designed as a foundation for other libraries to build upon rather than for direct use by end-users.
    from "wasi/file" include File
  7. Overview of the Grain Queue data structure

    The Queue module provides a FIFO (first-in-first-out) data structure where new values are added to the end and retrieved or removed from the beginning. The default implementation is mutable. For an immutable version, use the Immutable submodule.
    from "queue" include Queue
    
    let queue = Queue.fromList([0, 1])
    Queue.push(2, queue)
    assert Queue.pop(queue) == Some(0)
    assert Queue.pop(queue) == Some(1)
    assert Queue.pop(queue) == Some(2)
  8. Overview of Grain Buffer

    Buffers in Grain are data structures that automatically expand as data is appended, making them ideal for storing and operating on an unknown number of bytes. All set or append operations mutate the buffer.
    from "buffer" include Buffer
  9. Overview of the Rational module

    The Rational module provides utilities for working with the Rational type in Grain. Rational literals are denoted by the r suffix (e.g., 1/2r).
    from "rational" include Rational
    
    let half = 1/2r
    let threeQuarters = 3/4r
  10. Overview of the Grain Stack module

    The Stack module provides a LIFO (last-in-first-out) data structure where values are added, retrieved, and removed from the end. The default implementation is mutable. For an immutable version, use the Stack.Immutable submodule.
    from "stack" include Stack
  11. Overview of Grain Map

    A Map in Grain stores mutable key-value pairs. Any value type can be used as a key or a value. Operations on a Map mutate its internal state directly, meaning the map does not need to be re-assigned after modification. For an immutable implementation, use the Immutable submodule.
    from "map" include Map
  12. Overview of Grain Path module

    The Path module treats system paths as data representations and does not interact with the file system. It uses a POSIX-like grammar where / is the standard separator. Absolute paths can be rooted at / or Windows-style drive roots (e.g., C:/). The type system explicitly encodes whether a path is absolute or relative, and whether it refers to a file or a directory. Key rules include: paths referencing files must not have trailing slashes, while directory paths may. The segments . and .. are supported for current and parent directory navigation.