MyNixOS website logo
Description

Type-safe conversion of type literals into runtime values.

Literally is a minimal library that converts type literals into values using type-safe mechanisms. It provides a single literal function that leverages Haskell's type system to convert compile-time literals (numbers, strings, characters, booleans, tuples) into runtime values with compile-time correctness guarantees. The library supports numeric types with automatic bounds checking, string and character literals, boolean values, unit types, and tuple types.

Literally

CI

Literally is a minimal Haskell library that converts type literals into values. It provides type-safe literal conversion functionality using Haskell's advanced type system.

Overview

The literally library allows you to convert compile-time type literals (numbers, strings, characters, etc.) into runtime values in a type-safe manner. This is accomplished through a single literal function that leverages type-level programming to ensure correctness at compile time.

Installation

Add literally to your project's dependencies:

# In your package.yaml
dependencies:
  - literally

Or in your .cabal file:

build-depends: literally

Usage

Import the module and use the literal function with type annotations:

{-# LANGUAGE RequiredTypeArguments #-}
import Literally

-- Convert numeric literals
number :: Integer
number = literal 42

naturalNum :: Natural  
naturalNum = literal 123

-- Convert string literals
greeting :: String
greeting = literal "hello"

-- Convert character literals
letter :: Char
letter = literal 'x'

-- Convert boolean literals
truth :: Bool
truth = literal 'True

falsehood :: Bool  
falsehood = literal 'False

-- Convert unit type
unit :: ()
unit = literal ()

-- Works with tuples too
pair :: (Integer, String)
pair = literal (42, "hello")

How It Works

The library uses the FromType type class:

  • FromType: Defines how to convert from a type literal to a value, with an associated KnownType constraint.
Metadata

Version

0.2025.9.10

License

Platforms (76)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows