Skip to content
An experiment to bring type safety to the iconv library
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
src/Codec/Text/IConv
test
.gitignore
LICENSE
README.md
Setup.hs
iconv-typed.cabal
stack-7.8.yaml
stack.yaml

README.md

iconv-typed

An experiment in bringing type safety to the iconv package.

This is almost a drop-in replacement. Compare the original code from iconv:

{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Codec.Text.IConv

main :: IO ()
main = print $ convert "UTF-8" "LATIN1" "hello"

With the equivalent in iconv-typed:

{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Codec.Text.IConv.Typed

main :: IO ()
main = print $ convert @"UTF-8" @"LATIN1" "hello"

As a result, this code will compile and run only if the passed encoding resolves to a supported encoding (as retrieved at compile time by calling iconv -l). For example, the following won't compile:

main = print $ convert @"UFT-8" @"LATIN1" "hello"

As UFT is mispelled.

Using GHC < 8.0 that doesn't supports TypeInType? No problem, we've got you covered!

module Main where

import Codec.Text.IConv.Typed

main :: IO ()
main = print $ convert (E :: E "UTF-8") (E :: E "LATIN1") "hello"
You can’t perform that action at this time.