packages feed

extra-data-yj (empty) → 0.1.0.0

raw patch · 8 files changed

+317/−0 lines, 8 filesdep +basedep +extra-data-yjsetup-changed

Dependencies added: base, extra-data-yj

Files

+ ChangeLog.md view
@@ -0,0 +1,3 @@+# Changelog for extra-data-yj++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Yoshikuni Jujo (c) 2020++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 Yoshikuni Jujo 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,1 @@+# extra-data-yj
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ extra-data-yj.cabal view
@@ -0,0 +1,53 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.35.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: f409ea8b95e114cc0607b5dbb57c2eec726cd9ae3cb5d9d7adb923ada38bf021++name:           extra-data-yj+version:        0.1.0.0+synopsis:       Additional data types+description:    Please see the README on GitHub at <https://github.com/YoshikuniJujo/extra-data-yj#readme>+category:       Data+homepage:       https://github.com/YoshikuniJujo/extra-data-yj#readme+bug-reports:    https://github.com/YoshikuniJujo/extra-data-yj/issues+author:         Yoshikuni Jujo+maintainer:     PAF01143@nifty.ne.jp+copyright:      Yoshikuni Jujo+license:        BSD3+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    README.md+    ChangeLog.md++source-repository head+  type: git+  location: https://github.com/YoshikuniJujo/extra-data-yj++library+  exposed-modules:+      Data.List.Infinite+      Data.Or+  other-modules:+      Paths_extra_data_yj+  hs-source-dirs:+      src+  build-depends:+      base >=4.7 && <5+  default-language: Haskell2010++test-suite extra-data-yj-test+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  other-modules:+      Paths_extra_data_yj+  hs-source-dirs:+      test+  ghc-options: -threaded -rtsopts -with-rtsopts=-N+  build-depends:+      base >=4.7 && <5+    , extra-data-yj+  default-language: Haskell2010
+ src/Data/List/Infinite.hs view
@@ -0,0 +1,183 @@+{-# OPTIONS_GHC -Wall -fno-warn-tabs #-}++module Data.List.Infinite (+	-- * Definition+	Infinite(..), NonEmpty(..),+	-- * Basic functions+	append, uncons, concat,+	-- * List transformations+	intersperse, intercalate, subsequences,+	-- * Reducing lists (folds)+	foldr,+	-- * Scans+	scanl, scanl',+	-- * Infinite lists+	iterate, iterate', repeat, cycle, unfoldr,+	-- * Extracting sublits+	take, drop, splitAt, span, group, groupBy, inits,+	-- * Predicates+	isPrefixOf,+	-- * Searching+	partition,+	-- * Indexing lists+	index,+	-- * Zipping and unzipping lists+	zipWith, unzip,+	-- * "Set" operations+	delete, (\\),+	-- * Ordered lists+	insert, insertBy+	) where++import Prelude hiding (+	cycle, (++), concat, scanl, iterate, repeat,+	span, take, drop, splitAt, zipWith, unzip )++import Control.Arrow (first, second, (***))++import Data.List.NonEmpty (NonEmpty(..))++-- DEFINITION++infixr 5 :~++data Infinite a = a :~ Infinite a++instance Functor Infinite where f `fmap` (x :~ xs) = f x :~ (f <$> xs)++instance Applicative Infinite where+	pure x = x :~ pure x+	(f :~ fs) <*> (x :~ xs) = f x :~ (fs <*> xs)++instance Foldable Infinite where+	foldr op v (x :~ xs) = x `op` foldr op v xs++-- BASIC FUNCTIONS++append :: [a] -> Infinite a -> Infinite a+[] `append` ys = ys+(x : xs) `append` ys = x :~ (xs `append` ys)++uncons :: Infinite a -> (a, Infinite a)+uncons (x :~ xs) = (x, xs)++concat :: Infinite [a] -> Infinite a+concat ([] :~ xss) = concat xss+concat ((x : xs) :~ xss) = x :~ concat (xs :~ xss)++-- LIST TRANSFORMATIONS++intersperse :: a -> Infinite a -> Infinite a+intersperse x (y :~ ys) = y :~ x :~ intersperse x ys++intercalate :: [a] -> Infinite [a] -> Infinite a+intercalate xs (ys :~ yss) = ys `append` (xs `append` intercalate xs yss)++subsequences, nonEmptySubsequences :: Infinite a -> Infinite [a]+subsequences xs = [] :~ nonEmptySubsequences xs++nonEmptySubsequences (x :~ xs) =+	[x] :~ concat ((\ys -> [ys, x : ys]) <$> nonEmptySubsequences xs)++-- REDUCING LISTS (FOLDS)++-- SCANS++scanl, scanl' :: (b -> a -> b) -> b -> Infinite a -> Infinite b+scanl op z (x :~ xs) = z :~ scanl op (z `op` x) xs+scanl' op z (x :~ xs) = z `seq` z :~ scanl' op (z `op` x) xs++-- INFINITE LISTS++iterate, iterate' :: (a -> a) -> a -> Infinite a+iterate f x = x :~ iterate f (f x)+iterate' f x = x `seq` x :~ iterate f (f x)++repeat :: a -> Infinite a+repeat x = x :~ repeat x++cycle :: NonEmpty a -> Infinite a+cycle xs = ccl xs where+	ccl (y :| ys) = y :~ case ys of+		[] -> cycle xs+		(z : zs) -> ccl (z :| zs)++unfoldr :: (b -> (a, b)) -> b -> Infinite a+unfoldr f s = x :~ unfoldr f s' where (x, s') = f s++-- SUBLISTS++take :: Integral i => i -> Infinite a -> [a]+take n = fst . splitAt n++drop :: Integral i => i -> Infinite a -> Infinite a+drop n = snd . splitAt n++splitAt :: Integral i => i -> Infinite a -> ([a], Infinite a)+splitAt n xs | n < 1 = ([], xs)+splitAt n (x :~ xs) = (x :) `first` splitAt (n - 1) xs++span :: (a -> Bool) -> Infinite a -> ([a], Infinite a)+span p xa@(x :~ xs)+	| p x = (x :) `first` span p xs+	| otherwise = ([], xa)++group :: Eq a => Infinite a -> Infinite [a]+group = groupBy (==)++groupBy :: (a -> a -> Bool) -> Infinite a -> Infinite [a]+groupBy eq (x :~ xs) = (x : ys) :~ groupBy eq zs+	where (ys, zs) = span (x `eq`) xs++inits :: Infinite a -> Infinite [a]+inits (x :~ xs) = [] :~ ((x :) <$> inits xs)++-- PREDICATES++isPrefixOf :: Eq a => [a] -> Infinite a -> Bool+isPrefixOf [] _ = True+isPrefixOf (x : xs) (y :~ ys) = x == y && isPrefixOf xs ys++-- SEARCHING LISTS++partition :: (a -> Bool) -> Infinite a -> (Infinite a, Infinite a)+partition p (x :~ xs)+	| p x = (x :~) `first` partition p xs+	| otherwise = (x :~) `second` partition p xs++-- INDEXING LISTS++infixl 9 `index`++index :: Integral i => Infinite a -> i -> a+_ `index` n | n < 0 = error "negative index"+(x :~ _) `index` 0 = x+(_ :~ xs) `index` n = xs `index` (n - 1)++-- ZIPPING AND UNZIPPING LISTS++zipWith :: (a -> b -> c) -> Infinite a -> Infinite b -> Infinite c+zipWith op (x :~ xs) (y :~ ys) = (x `op` y) :~ zipWith op xs ys++unzip :: Infinite (a, b) -> (Infinite a, Infinite b)+unzip ((x, y) :~ xys) = (x :~) *** (y :~) $ unzip xys++-- SET OPERATIONS++delete :: Eq a => a -> Infinite a -> Infinite a+delete x (y :~ ys)+	| x == y = ys+	| otherwise = y :~ delete x ys++(\\) :: Eq a => Infinite a -> [a] -> Infinite a+(\\) = foldl $ flip delete++-- ORDERED LISTS++insert :: Ord a => a -> Infinite a -> Infinite a+insert = insertBy compare++insertBy :: (a -> a -> Ordering) -> a -> Infinite a -> Infinite a+insertBy cmp x ya@(y :~ ys) = case cmp x y of+	GT -> y :~ insertBy cmp x ys+	_ -> x :~ ya
+ src/Data/Or.hs view
@@ -0,0 +1,43 @@+{-# LANGUAGE LambdaCase #-}++{-# OPTIONS_GHC -Wall -fno-warn-tabs #-}++module Data.Or (+	Or(..), or, lefts, rights, fromLeft, fromRight, partitionOrs ) where++import Prelude hiding (or)++import Control.Arrow (first, second, (***))++data Or a b = L a | R b | LR a b deriving (Show, Read, Eq, Ord)++or :: (a -> c) -> (b -> c) -> (a -> b -> c) -> Or a b -> c+or f g h = \case L x -> f x; R y -> g y; LR x y -> h x y++lefts :: [Or a b] -> [a]+lefts [] = []+lefts (L x : os) = x : lefts os+lefts (R _ : os) = lefts os+lefts (LR x _ : os) = x : lefts os++rights :: [Or a b] -> [b]+rights [] = []+rights (L _ : os) = rights os+rights (R y : os) = y : rights os+rights (LR _ y : os) = y : rights os++fromLeft :: a -> Or a b -> a+fromLeft _ (L x) = x+fromLeft d (R _) = d+fromLeft _ (LR x _) = x++fromRight :: b -> Or a b -> b+fromRight d (L _) = d+fromRight _ (R y) = y+fromRight _ (LR _ y) = y++partitionOrs :: [Or a b] -> ([a], [b])+partitionOrs [] = ([], [])+partitionOrs (L x : os) = (x :) `first` partitionOrs os+partitionOrs (R y : os) = (y :) `second` partitionOrs os+partitionOrs (LR x y : os) = (x :) *** (y :) $ partitionOrs os
+ test/Spec.hs view
@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"