MyNixOS website logo
Description

Conversions between common string types, as well as Base16/Base32/Base64

Have you ever found yourself frustrated that you're spending 15-30% of your time in Haskell converting between string types, remembering which module has the toStrict function, importing Data.Text.Encoding and Data.Text.Lazy.Encoding qualified, spending time thinking about how to do Base64 encoding, etc.? Or tried to use one of the (excellent) typeclass-based string conversion libraries, only to find yourself adding awkward type signatures to avoid type-inferencing ambiguities?

This package exports a collection of functions that follow a simple pattern:

stringTypeAToStringTypeB :: a -> b

This way, if you import Data.String.FromTo unqualified, or as part of your Prelude, all you have to think about is which type you want to convert into which other type.

For convenience, this package also exposes conversions between Base16, Base32, and Base64-encoded strings.

string-fromto

A collection of predictably-named functions (e.g. byteStringToString) that convert between the common string types, as well as to and from Base16, Base32, and Base64.

Usage

import Data.String.FromTo -- or imported as part of your Prelude

str :: String
str = "Hi, I'm a string"

text :: Text
text = stringToText str

encoded :: ByteString
encoded = textToBase64ByteString text

decoded :: Either String Text
decoded = base64ByteStringToText encoded

Documentation

Hackage

License

BSD3

Motivation

Have you ever found yourself frustrated that you're spending 15-30% of your time in Haskell converting between string types, remembering which module has the toStrict function, importing Data.Text.Encoding and Data.Text.Lazy.Encoding qualified, spending time thinking about how to do Base64 encoding, etc.? Or tried to use one of the (excellent) typeclass-based string conversion libraries, only to find yourself adding awkward type signatures to avoid type-inferencing ambiguities?

This library exports a collection of functions that follow a simple pattern:

stringTypeAToStringTypeB :: a -> b

For example:


stringToByteString :: String -> ByteString

stringToLazyByteString :: String -> Lazy.ByteString

base64ByteStringToText :: ByteString -> Either String Text

This way, if you import this module unqualified, or as part of your Prelude, all you have to think about is which type you want to convert into which other type.

(Note that not every possible permutation has a function, just each one we've ever needed. If you need one that's not included, please submit a pull request to add it.)

Metadata

Version

1.0.0.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • 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-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