clist (empty) → 0.1.0.0
raw patch · 4 files changed
+90/−0 lines, 4 filesdep +basedep +base-unicode-symbolsdep +peanosetup-changed
Dependencies added: base, base-unicode-symbols, peano
Files
- Data/CList.hs +67/−0
- LICENSE +5/−0
- Setup.hs +2/−0
- clist.cabal +16/−0
+ Data/CList.hs view
@@ -0,0 +1,67 @@+{-# LANGUAGE StandaloneDeriving #-}++module Data.CList (module Data.Peano, CList (..), uncons, head, tail, init, last, reverse) where++import Prelude (Read, Show, fst, snd)++import Control.Applicative+import Control.Category.Unicode+import Data.Eq+import Data.Foldable+import Data.Functor+import Data.Monoid+import Data.Ord+import Data.Peano+import Data.Traversable+import Data.Typeable++infixr 5 :.++data CList n a where+ Nil :: CList Zero a+ (:.) :: a -> CList n a -> CList (Succ n) a++deriving instance (Eq a) => Eq (CList n a)+deriving instance (Ord a) => Ord (CList n a)+deriving instance (Show a) => Show (CList n a)+deriving instance Functor (CList n)+deriving instance Foldable (CList n)+deriving instance Traversable (CList n)+deriving instance Typeable CList++instance Monoid a => Monoid (CList Zero a) where+ mempty = Nil+ Nil `mappend` Nil = Nil++instance (Monoid a, Monoid (CList n a)) => Monoid (CList (Succ n) a) where+ mempty = mempty:.mempty+ (x:.xs) `mappend` (y:.ys) = x<>y:.xs<>ys++instance Applicative (CList Zero) where+ pure x = Nil+ Nil <*> Nil = Nil++instance (Applicative (CList n)) => Applicative (CList (Succ n)) where+ pure x = x :. pure x+ f:.fs <*> x:.xs = f x :. (fs <*> xs)++uncons :: CList (Succ n) a -> (a, CList n a)+uncons (x:.xs) = (x, xs)++head :: CList (Succ n) a -> a+head = fst ∘ uncons++tail :: CList (Succ n) a -> CList n a+tail = snd ∘ uncons++init :: CList (Succ n) a -> CList n a+init (x:.Nil) = Nil+init (x:.xs@(_:._)) = x:.init xs++last :: CList (Succ n) a -> a+last (x:.Nil) = x+last (x:.xs@(_:._)) = last xs++reverse :: CList n a -> CList n a+reverse Nil = Nil+reverse xs@(_:._) = liftA2 (:.) last (reverse ∘ init) xs
+ LICENSE view
@@ -0,0 +1,5 @@+© Unix year 45 (Strake = M Farkas-Dyck)++Leave to use, copy, modify, and distribute this work for any purpose is hereby granted if the above copyright notice and this license are included.++THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ clist.cabal view
@@ -0,0 +1,16 @@+name: clist+version: 0.1.0.0+synopsis: Counted list+homepage: https://github.com/strake/clist.hs+license: OtherLicense+license-file: LICENSE+author: M Farkas-Dyck+maintainer: strake888@gmail.com+category: Data+build-type: Simple+cabal-version: >=1.9.2++library+ exposed-modules: Data.CList+ extensions: TypeOperators, FlexibleContexts, FlexibleInstances, GADTs, DataKinds, DeriveFunctor, DeriveFoldable, DeriveTraversable+ build-depends: base >=4.8 && <4.9, base-unicode-symbols, peano