Made package stack compatible

Created and added stack.yaml and .gitignore files.
Relaxed the version dependency on 'binary' package in cabal file.  Is that OK?
Also brought the minimum cabal version to >=1.8, so I could add a test target that pulls in the library.
Changed all tabs to spaces - I don't know when the Haskell compiler started giving warnings about that.
This commit is contained in:
Scott Sedgwick 2017-07-28 14:17:39 +10:00
parent 6284c1a677
commit 8727ac25a5
15 changed files with 478 additions and 345 deletions

22
.gitignore vendored Normal file
View File

@ -0,0 +1,22 @@
### Haskell ###
dist
dist-*
cabal-dev
*.o
*.hi
*.chi
*.chs.h
*.dyn_o
*.dyn_hi
.hpc
.hsenv
.cabal-sandbox/
cabal.sandbox.config
*.prof
*.aux
*.hp
*.eventlog
.stack-work/
cabal.project.local
.HTF/

View File

@ -70,14 +70,20 @@ hGetContents h = do
str <- LBS.hGetContents h
return $ decodeLazyByteString ?enc str
-- | Like the normal 'System.IO.getContents', but decodes the input using an
-- encoding.
getContents :: (Encoding e,?enc :: e) => IO String
getContents = do
str <- LBS.getContents
return $ decodeLazyByteString ?enc str
-- | Like the normal 'System.IO.putStr', but decodes the input using an
-- encoding.
putStr :: (Encoding e,?enc :: e) => String -> IO ()
putStr = hPutStr stdout
-- | Like the normal 'System.IO.putStrLn', but decodes the input using an
-- encoding.
putStrLn :: (Encoding e,?enc :: e) => String -> IO ()
putStrLn = hPutStrLn stdout
@ -86,46 +92,72 @@ putStrLn = hPutStrLn stdout
hPutStr :: (Encoding e,?enc :: e) => Handle -> String -> IO ()
hPutStr h str = LBS.hPut h (encodeLazyByteString ?enc str)
-- | Like the normal 'System.IO.hPutStrLn', but decodes the input using an
-- encoding.
hPutStrLn :: (Encoding e,?enc :: e) => Handle -> String -> IO ()
hPutStrLn h str = do
LBS.hPut h (encodeLazyByteString ?enc str)
LBS.hPut h (encodeLazyByteString ?enc "\n")
-- | Like the normal 'System.IO.print', but decodes the input using an
-- encoding.
print :: (Encoding e,Show a,?enc :: e) => a -> IO ()
print = hPrint stdout
-- | Like the normal 'System.IO.hPrint', but decodes the input using an
-- encoding.
hPrint :: (Encoding e,Show a,?enc :: e) => Handle -> a -> IO ()
hPrint h x = hPutStrLn h (show x)
-- | Like the normal 'System.IO.readFile', but decodes the input using an
-- encoding.
readFile :: (Encoding e,?enc :: e) => FilePath -> IO String
readFile fn = LBS.readFile fn >>= return.(decodeLazyByteString ?enc)
-- | Like the normal 'System.IO.writeFile', but decodes the input using an
-- encoding.
writeFile :: (Encoding e,?enc :: e) => FilePath -> String -> IO ()
writeFile fn str = LBS.writeFile fn $ encodeLazyByteString ?enc str
-- | Like the normal 'System.IO.appendFile', but decodes the input using an
-- encoding.
appendFile :: (Encoding e,?enc :: e) => FilePath -> String -> IO ()
appendFile fn str = LBS.appendFile fn $ encodeLazyByteString ?enc str
-- | Like the normal 'System.IO.getChar', but decodes the input using an
-- encoding.
getChar :: (Encoding e,?enc :: e) => IO Char
getChar = hGetChar stdin
-- | Like the normal 'System.IO.hGetChar', but decodes the input using an
-- encoding.
hGetChar :: (Encoding e,?enc :: e) => Handle -> IO Char
hGetChar h = runReaderT (decodeChar ?enc) h
-- | Like the normal 'System.IO.getLine', but decodes the input using an
-- encoding.
getLine :: (Encoding e,?enc :: e) => IO String
getLine = hGetLine stdin
-- | Like the normal 'System.IO.hGetLine', but decodes the input using an
-- encoding.
hGetLine :: (Encoding e,?enc :: e) => Handle -> IO String
hGetLine h = do
line <- BS.hGetLine h
return $ decodeStrictByteString ?enc line
-- | Like the normal 'System.IO.putChar', but decodes the input using an
-- encoding.
putChar :: (Encoding e,?enc :: e) => Char -> IO ()
putChar = hPutChar stdout
-- | Like the normal 'System.IO.hPutChar', but decodes the input using an
-- encoding.
hPutChar :: (Encoding e,?enc :: e) => Handle -> Char -> IO ()
hPutChar h c = runReaderT (encodeChar ?enc c) h
-- | Like the normal 'System.IO.interact', but decodes the input using an
-- encoding.
interact :: (Encoding e,?enc :: e) => (String -> String) -> IO ()
interact f = do
line <- hGetLine stdin

View File

@ -9,7 +9,7 @@ Description:
Haskell has excellect handling of unicode, the Char type covers all unicode chars. Unfortunately, there's no possibility to read or write something to the outer world in an encoding other than ascii due to the lack of support for encodings. This library should help with that.
Category: Codec
Homepage: http://code.haskell.org/encoding/
Cabal-Version: >=1.6
Cabal-Version: >=1.8
Build-Type: Custom
Extra-Source-Files:
CHANGELOG
@ -45,7 +45,7 @@ Custom-Setup
Library
Build-Depends: array,
base >=3 && <5,
binary < 0.8,
binary,
bytestring,
containers,
extensible-exceptions,
@ -132,3 +132,16 @@ Library
C-Sources:
system_encoding.c
CPP-Options: -DSYSTEM_ENCODING
test-suite encoding-test
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: Main.hs
other-modules: Test.Tester
, Test.Tests
build-depends: base
, bytestring
, encoding
, HUnit
, QuickCheck
ghc-options: -threaded -rtsopts -with-rtsopts=-N

66
stack.yaml Normal file
View File

@ -0,0 +1,66 @@
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# http://docs.haskellstack.org/en/stable/yaml_configuration/
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-8.22
# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# extra-dep: true
# subdirs:
# - auto-update
# - wai
#
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
packages:
- '.'
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps: []
# Override default flag values for local packages and extra-deps
flags: {}
# Extra package databases containing global packages
extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.4"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor