| Copyright | (c) 2018 Composewell Technologies |
|---|---|
| License | BSD3 |
| Maintainer | streamly@composewell.com |
| Stability | pre-release |
| Portability | GHC |
| Safe Haskell | None |
| Language | Haskell2010 |
Streamly.Internal.Data.List
Description
Lists are just a special case of monadic streams. The stream type SerialT
Identity a can be used as a replacement for [a]. The List type in this
module is just a newtype wrapper around SerialT Identity for better type
inference when using the OverloadedLists GHC extension. List a provides
better performance compared to [a]. Standard list, string and list
comprehension syntax can be used with the List type by enabling
OverloadedLists, OverloadedStrings and MonadComprehensions GHC
extensions. There would be a slight difference in the Show and Read
strings of streamly list as compared to regular lists.
Conversion to stream types is free, any stream combinator can be used on
lists by converting them to streams. However, for convenience, this module
provides combinators that work directly on the List type.
List $ S.map (+ 1) $ toSerial (1 `Cons` Nil)
To convert a List to regular lists, you can use any of the following:
toList . toSerialandtoSerial . fromListtoListfrom Data.FoldabletoListandfromListfromIsListin GHC.Exts
If you have made use of Nil and Cons constructors in the code and you
want to replace streamly lists with standard lists, all you need to do is
import these definitions:
type List = []
pattern Nil <- [] where Nil = []
pattern Cons x xs = x : xs
infixr 5 Cons
{-# COMPLETE Cons, Nil #-}
See src/docs/streamly-vs-lists.md for more details and src/test/PureStreams.hs for comprehensive usage examples.
Documentation
List a is a replacement for [a].
Since: 0.6.0
Bundled Patterns
| pattern Nil :: List a | An empty list constructor and pattern that matches an empty Since: 0.6.0 |
| pattern Cons :: a -> List a -> List a infixr 5 | A list constructor and pattern that deconstructs a Since: 0.6.0 |
Instances
Just like List except that it has a zipping Applicative instance
and no Monad instance.
Since: 0.6.0
Constructors
| ZipList | |
Fields | |