| Copyright | (c) 2021 Kowainik |
|---|---|
| License | MPL-2.0 |
| Maintainer | Kowainik <xrom.xkov@gmail.com> |
| Stability | Stable |
| Portability | Portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Slist.Type
Description
The main Slist data types and instances. Provides smart constructors and a few
basic functions.
Documentation
Data type that represents sized list.
Size can be both finite or infinite, it is established using
Size data type.
Instances
| Monad Slist Source # | |
| Functor Slist Source # | |
| Applicative Slist Source # | |
| Foldable Slist Source # | Efficient implementation of |
Defined in Slist.Type Methods fold :: Monoid m => Slist m -> m # foldMap :: Monoid m => (a -> m) -> Slist a -> m # foldMap' :: Monoid m => (a -> m) -> Slist a -> m # foldr :: (a -> b -> b) -> b -> Slist a -> b # foldr' :: (a -> b -> b) -> b -> Slist a -> b # foldl :: (b -> a -> b) -> b -> Slist a -> b # foldl' :: (b -> a -> b) -> b -> Slist a -> b # foldr1 :: (a -> a -> a) -> Slist a -> a # foldl1 :: (a -> a -> a) -> Slist a -> a # elem :: Eq a => a -> Slist a -> Bool # maximum :: Ord a => Slist a -> a # minimum :: Ord a => Slist a -> a # | |
| Traversable Slist Source # | |
| Alternative Slist Source # | |
| IsList (Slist a) Source # | |
| Eq a => Eq (Slist a) Source # | Equality of sized lists is checked more efficiently due to the fact that the check on the list sizes can be done first for the constant time. |
| Ord a => Ord (Slist a) Source # | Lexicographical comparison of the lists. |
| Read a => Read (Slist a) Source # | |
| Show a => Show (Slist a) Source # | |
| Semigroup (Slist a) Source # | List appending. Use |
| Monoid (Slist a) Source # | |
| type Item (Slist a) Source # | |
Defined in Slist.Type | |
Smart constructors
slist :: [a] -> Slist a Source #
O(n). Constructs Slist from the given list.
>>>slist [1..5]Slist {sList = [1,2,3,4,5], sSize = Size 5}
Note: works with finite lists. Use infiniteSlist
to construct infinite lists.
infiniteSlist :: [a] -> Slist a Source #
Basic functions
size :: Slist a -> Size Source #
O(1). Returns the Size of the slist.
>>>size $ slist "Hello World!"Size 12>>>size $ infiniteSlist [1..]Infinity
isEmpty :: Slist a -> Bool Source #
O(1). Checks if Slist is empty
>>>isEmpty memptyTrue>>>isEmpty $ slist []True>>>isEmpty $ slist "Not Empty"False
cons :: a -> Slist a -> Slist a Source #
O(1). cons is Slist analogue to : for lists.
It adds the given element to the beginning of the list.
The following property is preserved:
size(consx xs) ==sizexs + 1
Examples:
>>>cons 'a' $ one 'b'Slist {sList = "ab", sSize = Size 2}
>>cons0 $infiniteSlist[1..] Slist {sList = [0..], sSize =Infinity}