From b33902c4a49aa4ac995b0893554002440084cef4 Mon Sep 17 00:00:00 2001 From: Andrew Martin Date: Mon, 1 Aug 2016 13:06:39 -0400 Subject: [PATCH] remove copy of Ap --- colonnade/colonnade.cabal | 1 - colonnade/hackage-docs.sh | 48 ++++++++++++++++++++++++++ colonnade/src/Colonnade/Internal/Ap.hs | 47 ------------------------- colonnade/src/Colonnade/Types.hs | 12 ++++--- 4 files changed, 55 insertions(+), 53 deletions(-) create mode 100755 colonnade/hackage-docs.sh delete mode 100644 colonnade/src/Colonnade/Internal/Ap.hs diff --git a/colonnade/colonnade.cabal b/colonnade/colonnade.cabal index a83c88e..4dac555 100644 --- a/colonnade/colonnade.cabal +++ b/colonnade/colonnade.cabal @@ -23,7 +23,6 @@ library Colonnade.Decoding.Text Colonnade.Decoding.ByteString.Char8 Colonnade.Internal - Colonnade.Internal.Ap build-depends: base >= 4.7 && < 5 , contravariant diff --git a/colonnade/hackage-docs.sh b/colonnade/hackage-docs.sh new file mode 100755 index 0000000..0ddbc20 --- /dev/null +++ b/colonnade/hackage-docs.sh @@ -0,0 +1,48 @@ +#!/bin/bash +set -e + +if [ "$#" -ne 1 ]; then + echo "Usage: scripts/hackage-docs.sh HACKAGE_USER" + exit 1 +fi + +user=$1 + +cabal_file=$(find . -maxdepth 1 -name "*.cabal" -print -quit) +if [ ! -f "$cabal_file" ]; then + echo "Run this script in the top-level package directory" + exit 1 +fi + +pkg=$(awk -F ":[[:space:]]*" 'tolower($1)=="name" { print $2 }' < "$cabal_file") +ver=$(awk -F ":[[:space:]]*" 'tolower($1)=="version" { print $2 }' < "$cabal_file") + +if [ -z "$pkg" ]; then + echo "Unable to determine package name" + exit 1 +fi + +if [ -z "$ver" ]; then + echo "Unable to determine package version" + exit 1 +fi + +echo "Detected package: $pkg-$ver" + +dir=$(mktemp -d build-docs.XXXXXX) +trap 'rm -r "$dir"' EXIT + +# cabal haddock --hoogle --hyperlink-source --html-location='/package/$pkg-$version/docs' --contents-location='/package/$pkg-$version' +stack haddock + +cp -R .stack-work/dist/x86_64-linux/Cabal-1.22.5.0/doc/html/$pkg/ $dir/$pkg-$ver-docs +# /home/andrew/.stack/snapshots/x86_64-linux/lts-5.17/7.10.3/doc/index.html + +tar cvz -C $dir --format=ustar -f $dir/$pkg-$ver-docs.tar.gz $pkg-$ver-docs + +curl -X PUT \ + -H 'Content-Type: application/x-tar' \ + -H 'Content-Encoding: gzip' \ + -u "$user" \ + --data-binary "@$dir/$pkg-$ver-docs.tar.gz" \ + "https://hackage.haskell.org/package/$pkg-$ver/docs" diff --git a/colonnade/src/Colonnade/Internal/Ap.hs b/colonnade/src/Colonnade/Internal/Ap.hs deleted file mode 100644 index 7831ca4..0000000 --- a/colonnade/src/Colonnade/Internal/Ap.hs +++ /dev/null @@ -1,47 +0,0 @@ -{-# LANGUAGE Rank2Types #-} -{-# LANGUAGE GADTs #-} -{-# OPTIONS_GHC -Wall #-} - -module Colonnade.Internal.Ap - ( Ap(..) - , runAp - , runAp_ - , liftAp - , hoistAp - , retractAp - ) where - -import Control.Applicative - --- | The free 'Applicative' for a 'Functor' @f@. -data Ap f a where - Pure :: a -> Ap f a - Ap :: f a -> Ap f (a -> b) -> Ap f b - -runAp :: Applicative g => (forall x. f x -> g x) -> Ap f a -> g a -runAp _ (Pure x) = pure x -runAp u (Ap f x) = flip id <$> u f <*> runAp u x - -runAp_ :: Monoid m => (forall a. f a -> m) -> Ap f b -> m -runAp_ f = getConst . runAp (Const . f) - -instance Functor (Ap f) where - fmap f (Pure a) = Pure (f a) - fmap f (Ap x y) = Ap x ((f .) <$> y) - -instance Applicative (Ap f) where - pure = Pure - Pure f <*> y = fmap f y - Ap x y <*> z = Ap x (flip <$> y <*> z) - -liftAp :: f a -> Ap f a -liftAp x = Ap x (Pure id) -{-# INLINE liftAp #-} - -hoistAp :: (forall a. f a -> g a) -> Ap f b -> Ap g b -hoistAp _ (Pure a) = Pure a -hoistAp f (Ap x y) = Ap (f x) (hoistAp f y) - -retractAp :: Applicative f => Ap f a -> f a -retractAp (Pure a) = pure a -retractAp (Ap x y) = x <**> retractAp y diff --git a/colonnade/src/Colonnade/Types.hs b/colonnade/src/Colonnade/Types.hs index 212c446..628cda0 100644 --- a/colonnade/src/Colonnade/Types.hs +++ b/colonnade/src/Colonnade/Types.hs @@ -87,13 +87,15 @@ instance Contravariant Headless where -- | This just actually a specialization of the free applicative. -- Check out @Control.Applicative.Free@ in the @free@ library to --- learn more about this. +-- learn more about this. The meanings of the fields are documented +-- slightly more in the source code. Unfortunately, haddock does not +-- play nicely with GADTs. data Decoding f content a where - DecodingPure :: !a -- ^ function + DecodingPure :: !a -- function -> Decoding f content a - DecodingAp :: !(f content) -- ^ header - -> !(content -> Either String a) -- ^ decoding function - -> !(Decoding f content (a -> b)) -- ^ next decoding + DecodingAp :: !(f content) -- header + -> !(content -> Either String a) -- decoding function + -> !(Decoding f content (a -> b)) -- next decoding -> Decoding f content b instance Functor (Decoding f content) where