basesystems: Implements encoders/decoders for basesystems

[ bsd3, data, library, numeric, serialization ] [ Propose Tags ] [ Report a vulnerability ]

This package implements encoder and decoder methods for numeric basesystems and provides definitions for common basesystems like base16, base58btc, base64, and more.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
ci

CI Build options

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 1.0.0.0, 1.0.0.1, 1.1.0.0, 1.2.0.0
Change log CHANGELOG.md
Dependencies array (>=0.5 && <0.6), base (>=4.18 && <5), bytestring (>=0.12 && <0.13), containers (>=0.7 && <8), text (>=2.1 && <2.2), xcodec (>=1.1 && <1.2) [details]
Tested with ghc ==9.6.7
License BSD-3-Clause
Author Zoey McBride
Maintainer zoeymcbride@mailbox.org
Uploaded by z0 at 2026-07-08T21:25:24Z
Category Numeric, Data, Serialization
Source repo head: git clone https://git.sr.ht/~z0/basesystems
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 41 total (10 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-07-08 [all 1 reports]

Readme for basesystems-1.2.0.0

[back to package description]

basesystems hackage.haskell.orgbuilds.sr.ht status

This project contains code for encoding/decoding numeric basesystems in Haskell. It's implemented in a strategy pattern style where BaseSystem is a type-class which provides the encoder and decoder methods on, for instance, ShortByteString, in Data.BaseSystem:

class BaseSystem a where
  encoder :: a -> ShortByteString -> String
  decoder :: a -> String -> Maybe ShortByteString

The library creates more BaseSystem classes with methods on normal ByteString in Data.BaseSystem.Strict and LazyByteString in Data.BaseSystem.Lazy. The basesystems passed as a to encoder and decoder are defined in Data.BaseSystem.DigitSystem. See the example.

Coverage

Eventually, This project aims to implement most if not all of the mulitbase specification's basesytems list.

Currently, the following basesystems are supported:

  • base2
  • base10
  • base16(upper/lower)
  • base32(upper/lower) w/pad + nopad
  • base32hex(lower/upper) w/pad + nopad
  • base58btc
  • base64 w/pad + nopad
  • base64url w/pad + nopad

Example

For an example of using basesystems, we can do the following in GHCI:

Set OverloadedStrings so strings can act as Text data and import the needed functions. Then import the basesystem functions and packValue from Data.BaseSystem.BinaryTranscoder to convert a number value directly into bytes.

λ> {-# LANGUAGE OverloadedStrings #-}
λ> import Data.BaseSystem (encoder, decoder, base2, base10, base16lower, base32lower)
λ> import Data.BaseSystem.BinaryTranscoder (packValue)

This shows how we can take the binary value of 123 and display it in various number systems.

λ> :t encoder
encoder :: BaseSystem a => a -> ShortByteString -> Text
λ> :t decoder
decoder :: BaseSystem a => a -> Text -> Maybe ShortByteString
λ> encoder base2 $ packValue (123 :: Int)
"1111011"
λ> encoder base16lower $ packValue (123 :: Int)
"7b"
λ> encoder base32lower $ packValue (123 :: Int)
"pm======"

We can also use encoders and decoders to translate one numeric representation to another.

λ> encoder base10 <$> decoder base2 "1111011"
Just "123"
λ> encoder base10 <$> decoder base16lower "7b"
Just "123"
λ> encoder base10 <$> decoder base32lower "pm======"
Just "123"

Development

Unit tests are provided on the main ipfshs repo, and bugs can be reported on ipfshs ticket tracker.

Licensing

The basesystems project and its modules are free software and licensed under the BSD 3-clause license. See LICENSE.txt.

Copyright © 2026 Zoey McBride | zoeymcbride@mailbox.org