Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adinapoli/iconv-typed
An experiment to bring type safety to the iconv library
https://github.com/adinapoli/iconv-typed
Last synced: 23 days ago
JSON representation
An experiment to bring type safety to the iconv library
- Host: GitHub
- URL: https://github.com/adinapoli/iconv-typed
- Owner: adinapoli
- License: bsd-3-clause
- Created: 2016-10-22T16:45:08.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-27T11:14:18.000Z (about 8 years ago)
- Last Synced: 2024-09-23T01:44:46.426Z (about 2 months ago)
- Language: Haskell
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## iconv-typed
An experiment in bringing type safety to the [iconv](http://hackage.haskell.org/package/iconv) package.
This is _almost_ a drop-in replacement. Compare the original code from `iconv`:
``` haskell
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
module Main whereimport Codec.Text.IConv
main :: IO ()
main = print $ convert "UTF-8" "LATIN1" "hello"
```With the equivalent in `iconv-typed`:
``` haskell
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
module Main whereimport 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:``` haskell
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!
``` haskell
module Main whereimport Codec.Text.IConv.Typed
main :: IO ()
main = print $ convert (E :: E "UTF-8") (E :: E "LATIN1") "hello"
```