literally: Type-safe conversion of type literals into runtime values.

[ data, library ] [ Propose Tags ] [ Report a vulnerability ]

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.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.2025.9.9, 0.2025.9.10
Change log CHANGELOG.md
Dependencies base (>=4.20 && <4.22) [details]
License 0BSD
Author
Maintainer Taylor Fausak
Category Data
Source repo head: git clone https://github.com/tfausak/literally
Uploaded by fozworth at 2025-09-10T17:45:09Z
Distributions
Downloads 5 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for literally-0.2025.9.10

[back to package description]

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