Copyright | (c) Zoltan Kelemen 2017 |
---|---|
License | BSD-style |
Maintainer | kelemzol@elte.hu |
Safe Haskell | Safe |
Language | Haskell2010 |
HtsSet is a Heterogenous Set wich can provide storing values with different type.
These modules are intended to be imported qualified, to avoid name clashes with Prelude functions, e.g.
import qualified Data.HtsSet as HSet
Synopsis
- data HtsSet
- empty :: HtsSet
- singleton :: forall a. Typeable a => a -> HtsSet
- null :: HtsSet -> Bool
- size :: HtsSet -> Int
- member :: forall proxy a. (Typeable a, Eq a) => a -> HtsSet -> Bool
- notMember :: forall proxy a. (Typeable a, Eq a) => a -> HtsSet -> Bool
- existTypeOf :: forall a. Typeable a => a -> HtsSet -> Bool
- existTypeOfP :: forall proxy a. Typeable a => proxy a -> HtsSet -> Bool
- existTypeOfP' :: forall a. Typeable a => Proxy a -> HtsSet -> Bool
- appl :: forall a b. Typeable a => b -> (a -> b) -> HtsSet -> b
- compliance :: forall a. Typeable a => Bool -> (a -> Bool) -> HtsSet -> Bool
- insert :: forall a. Typeable a => a -> HtsSet -> HtsSet
- lookup :: forall a. Typeable a => HtsSet -> Maybe a
- lookupWithDefault :: forall a. Typeable a => a -> HtsSet -> a
- update :: forall a. Typeable a => (a -> a) -> HtsSet -> HtsSet
- deleteByType :: forall a. Typeable a => a -> HtsSet -> HtsSet
- deleteByTypeP :: forall proxy a. Typeable a => proxy a -> HtsSet -> HtsSet
- deleteByTypeP' :: forall a. Typeable a => Proxy a -> HtsSet -> HtsSet
- deleteWhen :: forall a. Typeable a => (a -> Bool) -> HtsSet -> HtsSet
- data a :+ b = a :+ b
- class Append a where
- fill :: Append a => a -> HtsSet
- data Proxy (t :: k) :: forall k. k -> Type = Proxy
Documentation
null :: HtsSet -> Bool Source #
Is the HtsSet is empty?
null empty == True null (singleton "a") == False
size :: HtsSet -> Int Source #
The number of elements in the HtsSet
size empty == 0 size (singleton "a") == 1
member :: forall proxy a. (Typeable a, Eq a) => a -> HtsSet -> Bool Source #
The HtsSet is contain an element?
member (Proxy :: Proxy String) empty == False member (Proxy :: Proxy String) (singleton "a") == True
notMember :: forall proxy a. (Typeable a, Eq a) => a -> HtsSet -> Bool Source #
The HtsSet is not contain an element?
existTypeOf :: forall a. Typeable a => a -> HtsSet -> Bool Source #
The HtsSet is contain a same type of element?
let hs = insert "a" $ insert (2 :: Int) $ insert 'c' $ empty existTypeOf "string" hs == True
existTypeOfP :: forall proxy a. Typeable a => proxy a -> HtsSet -> Bool Source #
The HtsSet is contain a same type of element? (by proxy)
existTypeOfP' :: forall a. Typeable a => Proxy a -> HtsSet -> Bool Source #
The HtsSet is contain a same type of element? (by fixed proxy)
appl :: forall a b. Typeable a => b -> (a -> b) -> HtsSet -> b Source #
Apply a function to an element with a default value
appl "no ABC" (:"BC") $ singleton 'A' == "ABC" appl "no ABC" (:"BC") $ singleton "s" == "no ABC"
compliance :: forall a. Typeable a => Bool -> (a -> Bool) -> HtsSet -> Bool Source #
appl specialization
insert :: forall a. Typeable a => a -> HtsSet -> HtsSet Source #
Insert a new value in the HtsSet. If the a elem is already present in the HtsSet with type, the associated value is replaced with the supplied value
insert "a" $ insert (2 :: Int) $ insert 'c' $ empty
lookup :: forall a. Typeable a => HtsSet -> Maybe a Source #
Lookup a value from in the HtsSet
let hs = insert "a" $ insert (2 :: Int) $ insert 'c' $ empty lookup hs == Just "a" lookup hs == Just (2 :: Int) but lookup hs == Just 2 -- is False! Because the type of 2 is Num t => t not Int
lookupWithDefault :: forall a. Typeable a => a -> HtsSet -> a Source #
Lookup a value from in the HtsSet with a default value
update :: forall a. Typeable a => (a -> a) -> HtsSet -> HtsSet Source #
Update a value in HtsSet
let hs = insert "a" $ insert (2 :: Int) $ insert 'c' $ empty let hs' = update (++"b") hs lookup hs' == Just "ab"
deleteByType :: forall a. Typeable a => a -> HtsSet -> HtsSet Source #
Delete an element by type
(member 'c' $ deleteByType 'b' $ singleton 'c') == False
deleteByTypeP :: forall proxy a. Typeable a => proxy a -> HtsSet -> HtsSet Source #
Delete an element by type (by proxy)
(member 'c' $ deleteByTypeP (Proxy :: Proxy Char) $ singleton 'c') == False
deleteByTypeP' :: forall a. Typeable a => Proxy a -> HtsSet -> HtsSet Source #
Delete an element by type (by fixed proxy)
deleteWhen :: forall a. Typeable a => (a -> Bool) -> HtsSet -> HtsSet Source #
Delete an element by condition
Helper heterogeneous list for comfortable HtsSet building (with append and fill)
let hs = fill ("a" :+ 'c' :+ True :+ ()) lookup hs == Just 'c' use () to close the list lookup hs == Just () -- is False! let hs' = fill ("a" :+ 'c' :+ True :+ () :+ ()) lookup hs' == Just () -- is Ok
a :+ b infixr 5 |
data Proxy (t :: k) :: forall k. k -> Type #
Proxy
is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically,
is a safer alternative to the
Proxy
:: Proxy
a'undefined :: a'
idiom.
>>>
Proxy :: Proxy (Void, Int -> Int)
Proxy
Proxy can even hold types of higher kinds,
>>>
Proxy :: Proxy Either
Proxy
>>>
Proxy :: Proxy Functor
Proxy
>>>
Proxy :: Proxy complicatedStructure
Proxy
Instances
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Bounded (Proxy t) | Since: base-4.7.0.0 |
Enum (Proxy s) | Since: base-4.7.0.0 |
Eq (Proxy s) | Since: base-4.7.0.0 |
Ord (Proxy s) | Since: base-4.7.0.0 |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
Ix (Proxy s) | Since: base-4.7.0.0 |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Monoid (Proxy s) | Since: base-4.7.0.0 |