H∀L∃

Haskell's web ecosystem, ported to Lean 4 with maximalist typing.

CI Docs GitHub Stars License Last Commit Lean 4

257 compile-time theorems · 45 ported libraries · 241 Lean modules

Overview

hale ports 45 Haskell libraries (241 Lean modules) covering everything from foundational types to a full HTTP/1-2-3 web server stack. Unlike a minimal port, types encode correctness proofs, invariants, and guarantees wherever feasible:

  • Correctness: Lawful typeclasses (LawfulBifunctor, LawfulCategory, LawfulTraversable) with verified laws
  • Invariants: Ratio enforces positive denominator and coprimality in its type; NonEmpty guarantees length >= 1
  • Proofs: clamp returns {y : a // lo <= y && y <= hi}; Fixed.add_exact proves addition preserves precision
  • 257 compile-time verified theorems across 52 files, checked by the Lean 4 kernel

Quick Start

Add to your lakefile.toml:

[[require]]
name = "hale"
git = "<repository-url>"
rev = "main"

Then import:

import Hale
open Hale

Ported Libraries

Core Infrastructure

Lean PackageHaskell PackageDescription
Hale.BasebaseFoundational types, functors, monads, concurrency
Hale.ByteStringbytestringByte array operations (strict, lazy, builder)
Hale.Word8word8Word8 character classification
Hale.TimetimeClock and time types
Hale.STMstmSoftware transactional memory
Hale.DataDefaultdata-defaultDefault values
Hale.ResourceTresourcetResource management monad
Hale.UnliftIOunliftio-coreMonadUnliftIO
Hale.ConduitconduitComposable streaming data pipelines

Networking

Lean PackageHaskell PackageDescription
Hale.NetworknetworkPOSIX sockets with phantom state
Hale.IpRouteiprouteIP address types
Hale.RecvrecvSocket receive
Hale.StreamingCommonsstreaming-commonsStreaming network utilities
Hale.SimpleSendfilesimple-sendfilesendfile(2) wrapper
Hale.TLStlsTLS via OpenSSL FFI

HTTP

Lean PackageHaskell PackageDescription
Hale.HttpTypeshttp-typesHTTP methods, status, headers, URI
Hale.HttpDatehttp-dateHTTP date parsing
Hale.Http2http2HTTP/2 framing, HPACK, server
Hale.Http3http3HTTP/3 framing, QPACK
Hale.QUICquicQUIC transport
Hale.BsbHttpChunkedbsb-http-chunkedChunked transfer encoding
Hale.HttpClienthttp-clientHTTP client with pluggable transport
Hale.HttpConduithttp-conduitHTTP + Conduit integration
Hale.ReqreqType-safe HTTP client

Web Application Interface

Lean PackageHaskell PackageDescription
Hale.WAIwaiRequest/Response/Application/Middleware
Hale.WarpwarpHTTP/1.x server
Hale.WarpTLSwarp-tlsHTTPS via OpenSSL
Hale.WarpQUICwarp-quicHTTP/3 over QUIC
Hale.WaiExtrawai-extra36 middleware modules
Hale.WaiAppStaticwai-app-staticStatic file serving
Hale.WaiHttp2Extrawai-http2-extraHTTP/2 server push
Hale.WaiWebSocketswai-websocketsWebSocket WAI handler
Hale.WebSocketswebsocketsRFC 6455 WebSocket protocol

Utilities

Lean PackageHaskell PackageDescription
Hale.CaseInsensitivecase-insensitiveCase-insensitive strings
Hale.VaultvaultType-safe heterogeneous storage
Hale.AutoUpdateauto-updatePeriodic cached values
Hale.TimeManagertime-managerConnection timeout management
Hale.CookiecookieHTTP cookie parsing
Hale.MimeTypesmime-typesMIME type lookup
Hale.Base64base64-bytestringRFC 4648 codec
Hale.FastLoggerfast-loggerBuffered thread-safe logging
Hale.WaiLoggerwai-loggerWAI request logging
Hale.UnixCompatunix-compatPOSIX compatibility
Hale.AnsiTerminalansi-terminalTerminal ANSI codes
Hale.PSQueuespsqueuesPriority search queues

Data

Lean PackageHaskell PackageDescription
Hale.DataFramedataframe (adapted)Tabular data with typed columns, CSV I/O

Typing Philosophy

Lean 4 is a dependently-typed proof assistant that compiles to efficient native code. Hale leverages this to turn protocol specs, resource lifecycles, and algebraic laws into compile-time obligations -- verified by the kernel, then erased at runtime (zero overhead).

  • Phantom state machines: Socket (state : SocketState) makes it a type error to send on an unconnected socket or close an already-closed one (proof obligation: state != .closed, discharged by decide)
  • Indexed monads: AppM .pending .sent ResponseReceived enforces that a WAI application calls respond exactly once -- double-respond is a compile-time error, not a runtime crash
  • Proof-carrying structures: Ratio carries den_pos and coprime proofs; Settings carries timeout_pos -- all erased at runtime (zero cost)
  • Algebraic laws: 257 theorems (bimap_id, bind_assoc, map_id, connAction_http11_default, ...) verified by the Lean kernel

Documentation

Build & Test

nix-shell                               # Nix users: enter shell with OpenSSL + pkg-config
lake build                              # Build the library
lake exe hale                           # Run smoke tests
lake build hale-tests && lake exe hale-tests  # Run test suite
bash tests/cross-check/run-all.sh       # Cross-check with Haskell (requires GHC)

Requires OpenSSL headers for TLS support. On non-Nix systems, ensure pkg-config openssl works (e.g., brew install openssl pkg-config on macOS, apt install libssl-dev pkg-config on Debian/Ubuntu).

License

See LICENSE for details.