agreeing (empty) → 0.1.0.0
raw patch · 8 files changed
+173/−0 lines, 8 filesdep +agreeingdep +basedep +hspecsetup-changed
Dependencies added: agreeing, base, hspec
Files
- CHANGELOG.md +11/−0
- LICENSE +30/−0
- README.md +4/−0
- Setup.hs +2/−0
- agreeing.cabal +53/−0
- src/Data/Agreement.hs +46/−0
- test/LengthSpec.hs +25/−0
- test/Spec.hs +2/−0
+ CHANGELOG.md view
@@ -0,0 +1,11 @@+# Changelog for `agreeing`++All notable changes to this project will be documented in this file.++The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),+and this project adheres to the+[Haskell Package Versioning Policy](https://pvp.haskell.org/).++## 0.1.0.0 - 2023-03-15++ Initial version
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright James Cranch (c) 2023++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 Author name here 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.
+ README.md view
@@ -0,0 +1,4 @@+# agreeing++A simple data structure helping us ask questions of the following+sort: "does all this data have the same /BLANK/ and if so what is it?"
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ agreeing.cabal view
@@ -0,0 +1,53 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.35.0.+--+-- see: https://github.com/sol/hpack++name: agreeing+version: 0.1.0.0+synopsis: Idiomatic data structure for agreement+description: Please see the README on GitHub at <https://github.com/jcranch/agreeing#readme>+category: Data+homepage: https://github.com/jcranch/agreement#readme+bug-reports: https://github.com/jcranch/agreement/issues+author: James Cranch+maintainer: j.d.cranch@sheffield.ac.uk+copyright: 2023 James Cranch+license: BSD3+license-file: LICENSE+build-type: Simple+extra-source-files:+ README.md+ CHANGELOG.md++source-repository head+ type: git+ location: https://github.com/jcranch/agreement++library+ exposed-modules:+ Data.Agreement+ other-modules:+ Paths_agreeing+ hs-source-dirs:+ src+ ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints+ build-depends:+ base >=4.7 && <5+ default-language: Haskell2010++test-suite agreeing-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ LengthSpec+ Paths_agreeing+ hs-source-dirs:+ test+ ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N+ build-depends:+ agreeing+ , base >=4.7 && <5+ , hspec >=2.7 && <2.11+ default-language: Haskell2010
+ src/Data/Agreement.hs view
@@ -0,0 +1,46 @@+-- | A simple data structure helping us ask questions of the following+-- sort: "does all this data have the same <BLANK> and if so what is+-- it?"+--+-- For example:+-- > doTheseHaveTheSameLength :: [String] -> String+-- > doTheseHaveTheSameLength l = case foldMap (Somebody . length) of+-- > Somebody n -> "They all have length " <> show n+-- > Nobody -> "The lengths differ"+-- > Anybody -> "You didn't give me any strings"+module Data.Agreement (+ Agreement(..),+ getSomebody,+ ) where++import Data.Semigroup (Semigroup(..),+ stimesIdempotentMonoid)++-- | We have the following constructors:+-- * `Somebody` is a consistent choice of an element.+-- * `Nobody` is an inconsistent choice.+-- * `Anybody` is a failure to make any choice.+data Agreement a = Anybody | Somebody a | Nobody++-- | This picks out consistent choices as `Just`.+getSomebody :: Agreement a -> Maybe a+getSomebody (Somebody x) = Just x+getSomebody _ = Nothing++instance Functor Agreement where+ fmap _ Anybody = Anybody+ fmap f (Somebody x) = Somebody (f x)+ fmap _ Nobody = Nobody++instance (Eq a) => Semigroup (Agreement a) where+ Anybody <> x = x+ Nobody <> _ = Nobody+ Somebody x <> Anybody = Somebody x+ Somebody _ <> Nobody = Nobody+ Somebody x <> Somebody y+ | x == y = Somebody x+ | otherwise = Nobody+ stimes = stimesIdempotentMonoid++instance (Eq a) => Monoid (Agreement a) where+ mempty = Anybody
+ test/LengthSpec.hs view
@@ -0,0 +1,25 @@+module LengthSpec (spec) where++import Data.Agreement+import Test.Hspec+++doTheseHaveTheSameLength :: [String] -> String+doTheseHaveTheSameLength l = case foldMap (Somebody . length) l of+ Somebody n -> "All have length " <> show n+ Nobody -> "The lengths differ"+ Anybody -> "No strings provided"+++spec :: Spec+spec = do+ describe "Testing whether strings have same length" $ do+ it "works on strings of same length" $+ doTheseHaveTheSameLength ["cat", "dog", "rat", "cow"] `shouldBe` "All have length 3"+ it "works on single string" $+ doTheseHaveTheSameLength ["crocodile"] `shouldBe` "All have length 9"+ it "works on empty list" $+ doTheseHaveTheSameLength [] `shouldBe` "No strings provided"+ it "works on disparate strings" $+ doTheseHaveTheSameLength ["sheep", "sheep", "sheep", "Archangel Gabriel", "sheep"] `shouldBe` "The lengths differ"+
+ test/Spec.hs view
@@ -0,0 +1,2 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}+-- Autodiscover spec files