packages feed

papa-base-implement (empty) → 0.2.0

raw patch · 14 files changed

+553/−0 lines, 14 filesdep +QuickCheckdep +basedep +directorybuild-type:Customsetup-changed

Dependencies added: QuickCheck, base, directory, doctest, filepath, template-haskell

Files

+ LICENSE view
@@ -0,0 +1,77 @@+CSIRO Open Source Software License Agreement (variation of the BSD / MIT+License)++Copyright (c) 2016, Commonwealth Scientific and Industrial Research Organisation+(CSIRO) ABN 41 687 119 230.++All rights reserved. CSIRO is willing to grant you a license to this+aemo-webservice on the following terms, except where otherwise indicated for+third party material.++Redistribution and use of this software 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 CSIRO nor the names of its contributors may be used to+  endorse or promote products derived from this software without specific prior+  written permission of CSIRO.++EXCEPT AS EXPRESSLY STATED IN THIS AGREEMENT AND TO THE FULL EXTENT PERMITTED BY+APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS". CSIRO MAKES NO+REPRESENTATIONS, WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED,+INCLUDING BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS+REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE,+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, THE ABSENCE+OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT+DISCOVERABLE.++TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL CSIRO BE+LIABLE ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION FOR+BREACH OF CONTRACT, NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR+OTHER LIABILITY HOWSOEVER INCURRED.  WITHOUT LIMITING THE SCOPE OF THE PREVIOUS+SENTENCE THE EXCLUSION OF LIABILITY SHALL INCLUDE: LOSS OF PRODUCTION OR+OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS OF+ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR OTHER ECONOMIC+LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY+DAMAGES, ARISING OUT OF OR IN CONNECTION WITH THIS AGREEMENT, ACCESS OF THE+SOFTWARE OR ANY OTHER DEALINGS WITH THE SOFTWARE, EVEN IF CSIRO HAS BEEN ADVISED+OF THE POSSIBILITY OF SUCH CLAIM, LOSS, DAMAGES OR OTHER LIABILITY.++APPLICABLE LEGISLATION SUCH AS THE AUSTRALIAN CONSUMER LAW MAY APPLY+REPRESENTATIONS, WARRANTIES, OR CONDITIONS, OR IMPOSES OBLIGATIONS OR LIABILITY+ON CSIRO THAT CANNOT BE EXCLUDED, RESTRICTED OR MODIFIED TO THE FULL EXTENT SET+OUT IN THE EXPRESS TERMS OF THIS CLAUSE ABOVE "CONSUMER GUARANTEES".  TO THE+EXTENT THAT SUCH CONSUMER GUARANTEES CONTINUE TO APPLY, THEN TO THE FULL EXTENT+PERMITTED BY THE APPLICABLE LEGISLATION, THE LIABILITY OF CSIRO UNDER THE+RELEVANT CONSUMER GUARANTEE IS LIMITED (WHERE PERMITTED AT CSIRO'S OPTION) TO+ONE OF FOLLOWING REMEDIES OR SUBSTANTIALLY EQUIVALENT REMEDIES:++(a)               THE REPLACEMENT OF THE SOFTWARE, THE SUPPLY OF EQUIVALENT+                  SOFTWARE, OR SUPPLYING RELEVANT SERVICES AGAIN;+(b)               THE REPAIR OF THE SOFTWARE;+(c)               THE PAYMENT OF THE COST OF REPLACING THE+                  SOFTWARE, OF ACQUIRING EQUIVALENT SOFTWARE, HAVING THE+                  RELEVANT SERVICES SUPPLIED AGAIN, OR HAVING THE SOFTWARE+                  REPAIRED.++IN THIS CLAUSE, CSIRO INCLUDES ANY THIRD PARTY AUTHOR OR OWNER OF ANY PART OF+THE SOFTWARE OR MATERIAL DISTRIBUTED WITH IT.  CSIRO MAY ENFORCE ANY RIGHTS ON+BEHALF OF THE RELEVANT THIRD PARTY.++Third Party Components++The following third party components are distributed with the Software.  You+agree to comply with the license terms for these components as part of accessing+the Software.  Other third party software may also be identified in separate+files distributed with the Software.++___________________________________________________________________++___________________________________________________________________
+ Setup.lhs view
@@ -0,0 +1,44 @@+#!/usr/bin/env runhaskell+\begin{code}+{-# OPTIONS_GHC -Wall #-}+module Main (main) where++import Data.List ( nub )+import Data.Version ( showVersion )+import Distribution.Package ( PackageName(PackageName), PackageId, InstalledPackageId, packageVersion, packageName )+import Distribution.PackageDescription ( PackageDescription(), TestSuite(..) )+import Distribution.Simple ( defaultMainWithHooks, UserHooks(..), simpleUserHooks )+import Distribution.Simple.Utils ( rewriteFile, createDirectoryIfMissingVerbose )+import Distribution.Simple.BuildPaths ( autogenModulesDir )+import Distribution.Simple.Setup ( BuildFlags(buildVerbosity), fromFlag )+import Distribution.Simple.LocalBuildInfo ( withLibLBI, withTestLBI, LocalBuildInfo(), ComponentLocalBuildInfo(componentPackageDeps) )+import Distribution.Verbosity ( Verbosity )+import System.FilePath ( (</>) )++main :: IO ()+main = defaultMainWithHooks simpleUserHooks+  { buildHook = \pkg lbi hooks flags -> do+     generateBuildModule (fromFlag (buildVerbosity flags)) pkg lbi+     buildHook simpleUserHooks pkg lbi hooks flags+  }++generateBuildModule :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()+generateBuildModule verbosity pkg lbi = do+  let dir = autogenModulesDir lbi+  createDirectoryIfMissingVerbose verbosity True dir+  withLibLBI pkg lbi $ \_ libcfg -> do+    withTestLBI pkg lbi $ \suite suitecfg -> do+      rewriteFile (dir </> "Build_" ++ testName suite ++ ".hs") $ unlines+        [ "module Build_" ++ testName suite ++ " where"+        , "deps :: [String]"+        , "deps = " ++ (show $ formatdeps (testDeps libcfg suitecfg))+        ]+  where+    formatdeps = map (formatone . snd)+    formatone p = case packageName p of+      PackageName n -> n ++ "-" ++ showVersion (packageVersion p)++testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo -> [(InstalledPackageId, PackageId)]+testDeps xs ys = nub $ componentPackageDeps xs ++ componentPackageDeps ys++\end{code}
+ changelog view
@@ -0,0 +1,3 @@+0.2.0++* Initial release.
+ papa-base-implement.cabal view
@@ -0,0 +1,74 @@+name:               papa-base-implement+version:            0.2.0+license:            BSD3+license-file:       LICENSE+author:             Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ>+maintainer:         Tony Morris+copyright:          Copyright (c) 2017, Commonwealth Scientific and Industrial Research Organisation (CSIRO) ABN 41 687 119 230.+synopsis:           Useful base functions reimplemented+category:           Prelude+description:        Useful base functions reimplemented+homepage:           https://github.com/data61/papa-base-implement+bug-reports:        https://github.com/data61/papa-base-implement/issues+cabal-version:      >= 1.10+build-type:         Custom+extra-source-files: changelog++source-repository   head+  type:             git+  location:         git@github.com:data61/papa-base-implement.git++flag                small_base+  description:      Choose the new, split-up base package.++library+  default-language:+                    Haskell2010++  build-depends:+                    base >= 4.8 && < 5+                    +  ghc-options:+                    -Wall++  default-extensions:+                    NoImplicitPrelude++  hs-source-dirs:+                    src++  exposed-modules:+                    Papa.Base.Implement+                    Papa.Base.Implement.Control.Applicative+                    Papa.Base.Implement.Control.Monad+                    Papa.Base.Implement.Data.Bool+                    Papa.Base.Implement.Data.Foldable+                    Papa.Base.Implement.Data.Function+                    Papa.Base.Implement.Data.List+                    Papa.Base.Implement.Data.Monoid+                    Papa.Base.Implement.Data.Traversable+                    +test-suite doctests+  type:+                    exitcode-stdio-1.0++  main-is:+                    doctests.hs++  default-language:+                    Haskell2010++  build-depends:+                    base < 5 && >= 3+                    , doctest >= 0.9.7+                    , filepath >= 1.3+                    , directory >= 1.1+                    , QuickCheck >= 2.0+                    , template-haskell >= 2.8++  ghc-options:+                    -Wall+                    -threaded++  hs-source-dirs:+                    test
+ src/Papa/Base/Implement.hs view
@@ -0,0 +1,14 @@+{-# LANGUAGE NoImplicitPrelude #-}++module Papa.Base.Implement(+  module P+) where++import Papa.Base.Implement.Control.Applicative as P+import Papa.Base.Implement.Control.Monad as P+import Papa.Base.Implement.Data.Bool as P+import Papa.Base.Implement.Data.Foldable as P+import Papa.Base.Implement.Data.Function as P+import Papa.Base.Implement.Data.List as P+import Papa.Base.Implement.Data.Monoid as P+import Papa.Base.Implement.Data.Traversable as P
+ src/Papa/Base/Implement/Control/Applicative.hs view
@@ -0,0 +1,22 @@+{-# LANGUAGE NoImplicitPrelude #-}++module Papa.Base.Implement.Control.Applicative(+  const+, return+) where++import Control.Applicative(Applicative(pure))++const ::+  Applicative f =>+  a+  -> f a+const =+  pure++return ::+  Applicative f =>+  a+  -> f a+return =+  pure
+ src/Papa/Base/Implement/Control/Monad.hs view
@@ -0,0 +1,53 @@+{-# LANGUAGE NoImplicitPrelude #-}++module Papa.Base.Implement.Control.Monad(+  anyM+, allM+, findM+) where++import Data.Bool(Bool(False, True))+import Data.Maybe(Maybe(Nothing, Just))+import Control.Monad(Monad(return))++anyM ::+  Monad m =>+  (a -> m Bool)+  -> [a]+  -> m Bool+anyM _ []     =+  return False+anyM f (a:as) =+  do z <- f a+     if z+       then return True+       else anyM f as++allM ::+  Monad m =>+  (a -> m Bool)+  -> [a]+  -> m Bool+allM _ []     =+  return True+allM f (a:as) =+  do z <- f a+     if z+       then allM f as+       else return False++-- | Find an element satisfying a predicate+findM ::+  Monad m =>+  (a -> m Bool)+  -> [a]+  -> m (Maybe a)+findM _ [] =+  return Nothing+findM f (x:xs) =+  do b <- f x+     if b+       then+         return (Just x)+       else+         findM f xs
+ src/Papa/Base/Implement/Data/Bool.hs view
@@ -0,0 +1,111 @@+{-# LANGUAGE NoImplicitPrelude #-}++module Papa.Base.Implement.Data.Bool(+  if'+, (?.)+, (.?)+, (?<>)+, (<>?)+, (?<*>)+, (<*>?)+, (<||>)+, (<&&>)+) where++import Control.Applicative(Applicative(pure))+import Control.Category(Category(id))+import Control.Monad(Monad)+import Data.Bool(Bool(False, True), not)+import Data.Monoid++if' ::+  Bool+  -> a+  -> a+  -> a+if' True t _ =+  t+if' False _ f =+  f++(?.) ::+  Category c =>+  c a a+  -> Bool+  -> c a a+f ?. False =+  f+_ ?. True =+  id++(.?) ::+  Category c =>+  c a a+  -> Bool+  -> c a a+(.?) x y =+  (?.) x (not y)++(?<>) ::+  Monoid a =>+  a+  -> Bool+  -> a+f ?<> False =+  f+_ ?<> True =+  mempty++(<>?) ::+  Monoid a =>+  a+  -> Bool+  -> a+(<>?)  x y =+  (?<>) x (not y)++(?<*>) ::+  Applicative f =>+  (a -> f a)+  -> Bool+  -> a+  -> f a+f ?<*> False =+  f+_ ?<*> True =+  pure++(<*>?) ::+  Applicative f =>+  (a -> f a)+  -> Bool+  -> a+  -> f a+(<*>?) x y =+  (?<*>) x (not y)++(<||>) ::+  Monad m =>+  m Bool ->+  m Bool ->+  m Bool+p <||> q =+  do p' <- p+     if p'+       then+         pure True+       else+         q++(<&&>) ::+  Monad m =>+  m Bool ->+  m Bool ->+  m Bool+p <&&> q =+  do p' <- p+     if p'+       then+         q+       else+         pure False
+ src/Papa/Base/Implement/Data/Foldable.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE NoImplicitPrelude #-}++module Papa.Base.Implement.Data.Foldable(+  mapM_+, forM_+, sequence_+) where++import Control.Applicative(Applicative)+import Data.Foldable(Foldable, traverse_, sequenceA_)++mapM_ ::+  (Foldable t, Applicative f) =>+  (a -> f b)+  -> t a+  -> f ()+mapM_ =+  traverse_++forM_ ::+  (Foldable t, Applicative m) =>+  t a+  -> (a -> m b)+  -> m ()+forM_ a f =+  mapM_ f a+  +sequence_ ::+  (Foldable t, Applicative f) =>+  t (f a)+  -> f ()+sequence_ =+  sequenceA_
+ src/Papa/Base/Implement/Data/Function.hs view
@@ -0,0 +1,15 @@+{-# LANGUAGE NoImplicitPrelude #-}++module Papa.Base.Implement.Data.Function(+  flip+) where++import Data.Functor(Functor(fmap))++flip ::+  Functor f =>+  f (a -> b)+  -> a+  -> f b+flip f a =+  fmap (\k -> k a) f
+ src/Papa/Base/Implement/Data/List.hs view
@@ -0,0 +1,27 @@+{-# LANGUAGE NoImplicitPrelude #-}++module Papa.Base.Implement.Data.List(+  lookup+, (++)+) where++import Data.Foldable(Foldable(foldr))+import Data.Eq(Eq((==)))+import Data.Semigroup(Semigroup((<>)))+import Data.Maybe(Maybe(Nothing, Just))++lookup ::+  (Eq a, Foldable f) =>+  a+  -> f (a, b)+  -> Maybe b+lookup a =+  foldr (\(x, y) b -> if x == a then Just y else b) Nothing++(++) ::+  Semigroup a =>+  a+  -> a+  -> a+(++) =+  (<>)
+ src/Papa/Base/Implement/Data/Monoid.hs view
@@ -0,0 +1,15 @@+{-# LANGUAGE NoImplicitPrelude #-}++module Papa.Base.Implement.Data.Monoid(+  mconcat+) where++import Data.Foldable(Foldable, fold)+import Data.Monoid(Monoid)++mconcat ::+  (Monoid a, Foldable f) =>+  f a+  -> a+mconcat =+  fold
+ src/Papa/Base/Implement/Data/Traversable.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE NoImplicitPrelude #-}++module Papa.Base.Implement.Data.Traversable(+  mapM+, forM+, sequence+) where++import Control.Applicative(Applicative)+import Data.Traversable(Traversable(traverse, sequenceA))++mapM ::+  (Traversable t, Applicative f) =>+  (a -> f b)+  -> t a+  -> f (t b)+mapM =+  traverse++forM ::+  (Traversable t, Applicative f) =>+  t a+  -> (a -> f b)+  -> f (t b)+forM a f =+  traverse f a++sequence ::+  (Traversable t, Applicative f) =>+  t (f a)+  -> f (t a)+sequence =+  sequenceA
+ test/doctests.hs view
@@ -0,0 +1,32 @@+module Main where++import Build_doctests (deps)+import Control.Applicative+import Control.Monad+import Data.List+import System.Directory+import System.FilePath+import Test.DocTest++main ::+  IO ()+main =+  getSources >>= \sources -> doctest $+      "-isrc"+    : "-idist/build/autogen"+    : "-optP-include"+    : "-optPdist/build/autogen/cabal_macros.h"+    : "-hide-all-packages"+    : map ("-package="++) deps ++ sources++getSources :: IO [FilePath]+getSources = filter (isSuffixOf ".hs") <$> go "src"+  where+    go dir = do+      (dirs, files) <- getFilesAndDirectories dir+      (files ++) . concat <$> mapM go dirs++getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath])+getFilesAndDirectories dir = do+  c <- map (dir </>) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir+  (,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c