Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 17 additions & 68 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,76 +1,25 @@
# This file has been generated -- see https://github.com/hvr/multi-ghc-travis
language: c
sudo: false

cache:
directories:
- $HOME/.cabsnap
- $HOME/.cabal/packages

before_cache:
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.tar
env:
- STACK_YAML=stack.yaml

matrix:
include:
- env: CABALVER=1.24 GHCVER=8.0.1
compiler: ": #GHC 8.0.1"
addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.1], sources: [hvr-ghc]}}

before_install:
- unset CC
- export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:$PATH
addons:
apt:
packages: libgmp-dev

install:
- cabal --version
- echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
- if [ -f $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz ];
then
zcat $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz >
$HOME/.cabal/packages/hackage.haskell.org/00-index.tar;
fi
- travis_retry cabal update -v
- sed -i 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config
- cabal install --only-dependencies --enable-tests --enable-benchmarks --dry -v > installplan.txt
- sed -i -e '1,/^Resolving /d' installplan.txt; cat installplan.txt

# check whether current requested install-plan matches cached package-db snapshot
- if diff -u installplan.txt $HOME/.cabsnap/installplan.txt;
then
echo "cabal build-cache HIT";
rm -rfv .ghc;
cp -a $HOME/.cabsnap/ghc $HOME/.ghc;
cp -a $HOME/.cabsnap/lib $HOME/.cabsnap/share $HOME/.cabsnap/bin $HOME/.cabal/;
else
echo "cabal build-cache MISS";
rm -rf $HOME/.cabsnap;
mkdir -p $HOME/.ghc $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin;
cabal install --only-dependencies --enable-tests --enable-benchmarks;
fi
# stack
- mkdir -p ~/.local/bin
- export PATH=~/.local/bin:$PATH
- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
- stack --version

# snapshot package-db on cache miss
- if [ ! -d $HOME/.cabsnap ];
then
echo "snapshotting package-db to build-cache";
mkdir $HOME/.cabsnap;
cp -a $HOME/.ghc $HOME/.cabsnap/ghc;
cp -a $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin installplan.txt $HOME/.cabsnap/;
fi

# Here starts the actual work to be performed for the package under test;
# any command which exits with a non-zero exit code causes the build to fail.
script:
- if [ -f configure.ac ]; then autoreconf -i; fi
- cabal configure --enable-tests --enable-benchmarks -v2 # -v2 provides useful information for debugging
- cabal build # this builds all libraries and executables (including tests/benchmarks)
- cabal test
- cabal check
- cabal sdist # tests that a source-distribution can be generated

# Check that the resulting source distribution can be built & installed.
# If there are no other `.tar.gz` files in `dist`, this can be even simpler:
# `cabal install --force-reinstalls dist/*-*.tar.gz`
- SRC_TGZ=$(cabal info . | awk '{print $2;exit}').tar.gz &&
(cd dist && cabal install --force-reinstalls "$SRC_TGZ")
- stack setup --no-terminal
- stack build --ghc-options=-Werror --no-terminal
- stack test --ghc-options=-Werror --no-terminal --coverage
- stack haddock --no-terminal

# EOF
cache:
directories:
- $HOME/.stack
1 change: 1 addition & 0 deletions bookkeeper-aeson/.ghci
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:set -isrc -itest -idoctest/ghci-wrapper/src
4 changes: 4 additions & 0 deletions bookkeeper-aeson/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dist/
/dist-newstyle/
/.stack-work/

30 changes: 30 additions & 0 deletions bookkeeper-aeson/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Julian K. Arni (c) 2015

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Julian K. Arni nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File renamed without changes.
74 changes: 74 additions & 0 deletions bookkeeper-aeson/bookkeeper-aeson.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
-- This file has been generated from package.yaml by hpack version 0.15.0.
--
-- see: https://github.com/sol/hpack

name: bookkeeper-aeson
version: 0.1.0.0
synopsis: Aeson instances for bookkeeper
description: This package provides ToJSON and FromJSON instances for bookkeeper's @Book@ type.
homepage: http://github.com/turingjump/bookkeeper#readme
bug-reports: https://github.com/jkarni/bookkeeper-aeson/issues
author: Julian K. Arni
maintainer: jkarni@gmail.com
copyright: (c) Julian K. Arni
license: BSD3
license-file: LICENSE
tested-with: GHC == 8.0.2
build-type: Simple
cabal-version: >= 1.10

source-repository head
type: git
location: https://github.com/jkarni/bookkeeper-aeson

library
hs-source-dirs:
src
default-extensions: AutoDeriveTypeable ConstraintKinds DataKinds DefaultSignatures DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable FlexibleContexts FlexibleInstances FunctionalDependencies GADTs KindSignatures MultiParamTypeClasses OverloadedStrings OverloadedLabels RankNTypes ScopedTypeVariables TypeFamilies TypeOperators MagicHash
ghc-options: -Wall
build-depends:
base >= 4.9 && < 4.10
, aeson
, bookkeeper
, text
exposed-modules:
Bookkeeper.Aeson
default-language: Haskell2010

test-suite doctest
type: exitcode-stdio-1.0
main-is: Doctest.hs
hs-source-dirs:
test
default-extensions: AutoDeriveTypeable ConstraintKinds DataKinds DefaultSignatures DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable FlexibleContexts FlexibleInstances FunctionalDependencies GADTs KindSignatures MultiParamTypeClasses OverloadedStrings OverloadedLabels RankNTypes ScopedTypeVariables TypeFamilies TypeOperators MagicHash
ghc-options: -Wall
build-depends:
base >= 4.9 && < 4.10
, aeson
, bookkeeper
, text
, doctest >= 0.9 && < 0.12
, Glob >= 0.7 && < 0.8
, yaml == 0.8.*
other-modules:
Spec
default-language: Haskell2010

test-suite spec
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs:
test
default-extensions: AutoDeriveTypeable ConstraintKinds DataKinds DefaultSignatures DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable FlexibleContexts FlexibleInstances FunctionalDependencies GADTs KindSignatures MultiParamTypeClasses OverloadedStrings OverloadedLabels RankNTypes ScopedTypeVariables TypeFamilies TypeOperators MagicHash
ghc-options: -Wall
build-depends:
base >= 4.9 && < 4.10
, aeson
, bookkeeper
, text
, bookkeeper-aeson
, hspec > 2 && < 3
, QuickCheck >= 2.8 && < 2.10
other-modules:
Doctest
default-language: Haskell2010
65 changes: 65 additions & 0 deletions bookkeeper-aeson/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: bookkeeper-aeson
version: 0.1.0.0
synopsis: Aeson instances for bookkeeper
description: >
This package provides ToJSON and FromJSON instances for bookkeeper's
@Book@ type.
homepage: http://github.com/turingjump/bookkeeper#readme
license: BSD3
license-file: LICENSE
author: Julian K. Arni
maintainer: jkarni@gmail.com
copyright: (c) Julian K. Arni
github: jkarni/bookkeeper-aeson
tested-with: GHC == 8.0.2

ghc-options: -Wall

dependencies:
- base >= 4.9 && < 4.10
- aeson
- bookkeeper
- text

default-extensions:
- AutoDeriveTypeable
- ConstraintKinds
- DataKinds
- DefaultSignatures
- DeriveFoldable
- DeriveFunctor
- DeriveGeneric
- DeriveTraversable
- FlexibleContexts
- FlexibleInstances
- FunctionalDependencies
- GADTs
- KindSignatures
- MultiParamTypeClasses
- OverloadedStrings
- OverloadedLabels
- RankNTypes
- ScopedTypeVariables
- TypeFamilies
- TypeOperators
- MagicHash

library:
source-dirs: src
other-modules: []

tests:
spec:
main: Spec.hs
source-dirs: test
dependencies:
- bookkeeper-aeson
- hspec > 2 && < 3
- QuickCheck >= 2.8 && < 2.10
doctest:
main: Doctest.hs
source-dirs: test
dependencies:
- doctest >= 0.9 && < 0.12
- Glob >= 0.7 && < 0.8
- yaml == 0.8.*
48 changes: 48 additions & 0 deletions bookkeeper-aeson/src/Bookkeeper/Aeson.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Bookkeeper.Aeson where

import Bookkeeper
import Bookkeeper.Internal.Types
import Data.Aeson
import Data.Bifunctor
import Data.Proxy
import qualified Data.Text as T
import GHC.TypeLits

-- | @ToJSON@ instance for @Book@s. Does the obvious thing:
--
-- >>> encode julian
-- "{\"age\":28,\"name\":\"Julian K. Arni\"}"
instance (All (ToJSON `Compose` f) a, BKeys a) => ToJSON (Book' f a) where
toJSON b = object $ first T.pack <$> list
where
list = bcollapseWithKeys
$ bmapConstraint (Proxy :: Proxy (ToJSON `Compose` f)) (Const . toJSON) b

-- | @FromJSON@ instance for @Book@s. Does the obvious thing:
--
-- >>> decode "{\"age\":28,\"name\":\"Julian K. Arni\"}" :: Maybe Person
-- Just Book {#age = Identity 28, #name = Identity "Julian K. Arni"}
instance {-# OVERLAPPING #-}
(KnownSymbol key, FromJSON (f value))
=> FromJSON (Book' f '[key :=> value]) where
parseJSON (Object v) = go <$> v .: key
where
key = T.pack $ symbolVal (Proxy :: Proxy key)
go x = BCons x BNil
parseJSON _ = fail "expecting object"

instance {-# OVERLAPPABLE #-}
(KnownSymbol key, FromJSON (f value), FromJSON (Book' f rest))
=> FromJSON (Book' f (key :=> value ': rest)) where
parseJSON o@(Object v) = go $ v .: key
where
key = T.pack $ symbolVal (Proxy :: Proxy key)
go x = BCons <$> x <*> parseJSON o
parseJSON _ = fail "expecting object"

-- $setup
-- >>> import Data.Function ((&))
-- >>> type Person = Book '[ "name" :=> String , "age" :=> Int ]
-- >>> let julian :: Person = emptyBook & #age =: 28 & #name =: "Julian K. Arni"
26 changes: 26 additions & 0 deletions bookkeeper-aeson/test/Doctest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Main (main) where

-- Runs doctest on all files in "src" dir. Assumes:
-- (a) You are using hpack
-- (b) The top-level "default-extensions" are the only extensions besides the
-- ones in the files.

import System.FilePath.Glob (glob)
import Test.DocTest (doctest)
import Data.Yaml

newtype Exts = Exts { getExts :: [String] }
deriving (Eq, Show, Read)

instance FromJSON Exts where
parseJSON (Object v) = Exts <$> v .: "default-extensions"
parseJSON _ = fail "expecting object"

main :: IO ()
main = do
hpack' <- decodeFile "package.yaml"
hpack <- case hpack' of
Nothing -> return $ Exts []
Just v -> return v
files <- glob "src/**/*.hs"
doctest $ files ++ fmap ("-X" ++) (getExts hpack)
File renamed without changes.
30 changes: 30 additions & 0 deletions bookkeeper/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Julian K. Arni (c) 2015

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Julian K. Arni nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions bookkeeper/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
3 changes: 2 additions & 1 deletion bench/Main.hs → bookkeeper/bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ module Main where

import Bookkeeper
import Criterion.Main
import GHC.Prim

type PersonB = Book '[ "name" :=> String, "age" :=> Int ]
data PersonR = PersonR { name :: String, age :: {-# NOUNPACK #-} Int } deriving (Eq, Show)
data PersonR = PersonR { name :: !String, age :: {-# NOUNPACK #-} !Int } deriving (Eq, Show)

pb :: PersonB
pb = emptyBook
Expand Down
Loading