Copyright | (c) Donnacha Oisín Kidney 2020 |
---|---|
License | Apache |
Maintainer | mail@doisinkidney.com |
Stability | experimental |
Portability | ghc |
Safe Haskell | None |
Language | Haskell2010 |
This module provides a simple list type isomorphic to Haskell's
standard []
, but which is defined in terms of a non-empty list
type. This can make moving between one type and another
easier.
Synopsis
- data Star a
- pattern (:*) :: a -> Star a -> Star a
- data Plus a = (:-) {}
- filter :: Foldable f => (a -> Bool) -> f a -> Star a
- reverse :: Star a -> Star a
- uncons :: Star a -> Maybe (Plus a)
- take :: Int -> Star a -> Star a
- (!!) :: Star a -> Int -> a
- unfoldr :: (b -> Maybe (a, b)) -> b -> Star a
- scanr :: Foldable f => (a -> b -> b) -> b -> f a -> Plus b
- scanl :: (b -> a -> b) -> b -> Star a -> Plus b
- prescanl :: (b -> a -> b) -> b -> Star a -> Star b
- prescanr :: (a -> b -> b) -> b -> Star a -> Star b
- sortBy :: (a -> a -> Ordering) -> Star a -> Star a
- sortOn :: Ord b => (a -> b) -> Star a -> Star a
- sort :: Ord a => Star a -> Star a
The list type
A list, based on the Kleene star.
This type is isomorphic to Haskell's standard []
type, so it can be used
in the same way.
Instances
Monad Star Source # | |
Functor Star Source # | |
MonadFix Star Source # | |
Defined in Data.List.Kleene.Internal | |
Applicative Star Source # | |
Foldable Star Source # | |
Defined in Data.List.Kleene.Internal fold :: Monoid m => Star m -> m # foldMap :: Monoid m => (a -> m) -> Star a -> m # foldMap' :: Monoid m => (a -> m) -> Star a -> m # foldr :: (a -> b -> b) -> b -> Star a -> b # foldr' :: (a -> b -> b) -> b -> Star a -> b # foldl :: (b -> a -> b) -> b -> Star a -> b # foldl' :: (b -> a -> b) -> b -> Star a -> b # foldr1 :: (a -> a -> a) -> Star a -> a # foldl1 :: (a -> a -> a) -> Star a -> a # elem :: Eq a => a -> Star a -> Bool # maximum :: Ord a => Star a -> a # | |
Traversable Star Source # | |
Eq1 Star Source # | |
Ord1 Star Source # | |
Defined in Data.List.Kleene.Internal | |
Show1 Star Source # | |
MonadZip Star Source # | |
Alternative Star Source # | |
MonadPlus Star Source # | |
IsList (Star a) Source # | |
Eq a => Eq (Star a) Source # | |
Data a => Data (Star a) Source # | |
Defined in Data.List.Kleene.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Star a -> c (Star a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Star a) # toConstr :: Star a -> Constr # dataTypeOf :: Star a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Star a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Star a)) # gmapT :: (forall b. Data b => b -> b) -> Star a -> Star a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Star a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Star a -> r # gmapQ :: (forall d. Data d => d -> u) -> Star a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Star a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Star a -> m (Star a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Star a -> m (Star a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Star a -> m (Star a) # | |
Ord a => Ord (Star a) Source # | |
Show a => Show (Star a) Source # | |
Generic (Star a) Source # | |
Semigroup (Star a) Source # | |
Monoid (Star a) Source # | |
NFData a => NFData (Star a) Source # | |
Defined in Data.List.Kleene.Internal | |
type Rep (Star a) Source # | |
Defined in Data.List.Kleene.Internal type Rep (Star a) = D1 ('MetaData "Star" "Data.List.Kleene.Internal" "kleene-list-0.1.0.0-inplace" 'False) (C1 ('MetaCons "Nil" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Cons" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Plus a)))) | |
type Item (Star a) Source # | |
Defined in Data.List.Kleene.Internal |
pattern (:*) :: a -> Star a -> Star a infixr 5 Source #
A pattern for building up star lists as cons-lists.
>>>
1 :* 2 :* 3 :* Nil
[1,2,3]
A non-empty list type, based on the Kleene plus.
This type is isomorphic to NonEmpty
type, so it
can be used in the same way.
Instances
Monad Plus Source # | |
Functor Plus Source # | |
MonadFix Plus Source # | |
Defined in Data.List.Kleene.Internal | |
Applicative Plus Source # |
|
Foldable Plus Source # | |
Defined in Data.List.Kleene.Internal fold :: Monoid m => Plus m -> m # foldMap :: Monoid m => (a -> m) -> Plus a -> m # foldMap' :: Monoid m => (a -> m) -> Plus a -> m # foldr :: (a -> b -> b) -> b -> Plus a -> b # foldr' :: (a -> b -> b) -> b -> Plus a -> b # foldl :: (b -> a -> b) -> b -> Plus a -> b # foldl' :: (b -> a -> b) -> b -> Plus a -> b # foldr1 :: (a -> a -> a) -> Plus a -> a # foldl1 :: (a -> a -> a) -> Plus a -> a # elem :: Eq a => a -> Plus a -> Bool # maximum :: Ord a => Plus a -> a # | |
Traversable Plus Source # | |
Eq1 Plus Source # | |
Ord1 Plus Source # | |
Defined in Data.List.Kleene.Internal | |
Show1 Plus Source # | |
MonadZip Plus Source # | |
IsList (Plus a) Source # | |
Eq a => Eq (Plus a) Source # | |
Data a => Data (Plus a) Source # | |
Defined in Data.List.Kleene.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Plus a -> c (Plus a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Plus a) # toConstr :: Plus a -> Constr # dataTypeOf :: Plus a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Plus a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Plus a)) # gmapT :: (forall b. Data b => b -> b) -> Plus a -> Plus a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Plus a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Plus a -> r # gmapQ :: (forall d. Data d => d -> u) -> Plus a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Plus a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Plus a -> m (Plus a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Plus a -> m (Plus a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Plus a -> m (Plus a) # | |
Ord a => Ord (Plus a) Source # | |
Show a => Show (Plus a) Source # | |
Generic (Plus a) Source # | |
Semigroup (Plus a) Source # | |
NFData a => NFData (Plus a) Source # | |
Defined in Data.List.Kleene.Internal | |
type Rep (Plus a) Source # | |
Defined in Data.List.Kleene.Internal type Rep (Plus a) = D1 ('MetaData "Plus" "Data.List.Kleene.Internal" "kleene-list-0.1.0.0-inplace" 'False) (C1 ('MetaCons ":-" 'PrefixI 'True) (S1 ('MetaSel ('Just "head") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "tail") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Star a)))) | |
type Item (Plus a) Source # | |
Defined in Data.List.Kleene.Internal |
Utility functions
(!!) :: Star a -> Int -> a Source #
Index into a list.
>>>
[0..] !! 3
3
>>>
[0..5] !! 6
*** Exception: index: empty list!
Building lists
scans
prescanl :: (b -> a -> b) -> b -> Star a -> Star b Source #
Like scanl
, but without including the initial element in the output.
>>>
prescanl (+) 0 [1,2,3]
[1,3,6]
prescanr :: (a -> b -> b) -> b -> Star a -> Star b Source #
Like scanr
, but without including the initial element in the output.
>>>
prescanr (+) 0 [1,2,3]
[6,5,3]
Sorting
sortBy :: (a -> a -> Ordering) -> Star a -> Star a Source #
Sort given a comparison function. Stable. \(\mathcal{O}(n \log n)\).
>>>
sortBy (\x y -> compare (fst x) (fst y)) [(4,1),(3,2),(1,3),(3,4)]
[(1,3),(3,2),(3,4),(4,1)]