Copyright | (c) gspia 2020- |
---|---|
License | BSD |
Maintainer | gspia |
Safe Haskell | Safe |
Language | Haskell2010 |
Fcf.Data.Set
Set provides an interface which is similar to the that given by the containers-package. If a method is missing here that you need, please do open up an issue or better, make a PR.
Many of the examples are from containers-package. The internal representation is based on lists. We hope that a more efficient one will be used one day.
Synopsis
- data Set a = Set [a]
- data Member :: v -> Set v -> Exp Bool
- data NotMember :: v -> Set v -> Exp Bool
- data Null :: Set v -> Exp Bool
- data Size :: Set v -> Exp Nat
- data IsSubsetOf :: Set a -> Set a -> Exp Bool
- data IsProperSubsetOf :: Set a -> Set a -> Exp Bool
- data Empty :: Exp (Set v)
- data Singleton :: v -> Exp (Set v)
- data Insert :: v -> Set v -> Exp (Set v)
- data Delete :: v -> Set v -> Exp (Set v)
- data PowerSet :: Set a -> Exp (Set (Set a))
- data Union :: Set v -> Set v -> Exp (Set v)
- data Difference :: Set v -> Set v -> Exp (Set v)
- data Intersection :: Set v -> Set v -> Exp (Set v)
- data FromList :: [v] -> Exp (Set v)
- data ToList :: Set v -> Exp [v]
Documentation
Set-definition.
Set [a] |
Instances
type Eval (Empty :: Set v -> Type) Source # | |
type Eval (Singleton v :: Set a -> Type) Source # | |
type Eval (FromList lst :: Set a -> Type) Source # | |
type Eval (PowerSet (Set lst) :: Set (Set v) -> Type) Source # | |
type Eval (Insert v (Set lst) :: Set a -> Type) Source # | |
type Eval (Delete v (Set lst) :: Set a -> Type) Source # | |
type Eval (Union (Set lst1) (Set lst2) :: Set a -> Type) Source # | |
type Eval (Difference (Set lst1) (Set lst2) :: Set a -> Type) Source # | |
Defined in Fcf.Data.Set | |
type Eval (Intersection (Set lst1) (Set lst2) :: Set a -> Type) Source # | |
Defined in Fcf.Data.Set |
Query
data Member :: v -> Set v -> Exp Bool Source #
Member
Example
>>>
:kind! Eval (Member 5 =<< FromList '[5, 3])
Eval (Member 5 =<< FromList '[5, 3]) :: Bool = 'True>>>
:kind! Eval (Member 7 =<< FromList '[5, 3])
Eval (Member 7 =<< FromList '[5, 3]) :: Bool = 'False
data NotMember :: v -> Set v -> Exp Bool Source #
NotMember
Example
>>>
:kind! Eval (NotMember 5 =<< FromList '[5, 3])
Eval (NotMember 5 =<< FromList '[5, 3]) :: Bool = 'False>>>
:kind! Eval (NotMember 7 =<< FromList '[5, 3])
Eval (NotMember 7 =<< FromList '[5, 3]) :: Bool = 'True
data Null :: Set v -> Exp Bool Source #
Null
Example
>>>
:kind! Eval (Null =<< FromList '[5, 3])
Eval (Null =<< FromList '[5, 3]) :: Bool = 'False>>>
:kind! Eval (Null =<< Empty)
Eval (Null =<< Empty) :: Bool = 'True
data Size :: Set v -> Exp Nat Source #
Size
Example
>>>
:kind! Eval (Size =<< FromList '[5, 3])
Eval (Size =<< FromList '[5, 3]) :: Nat = 2
data IsSubsetOf :: Set a -> Set a -> Exp Bool Source #
IsSubsetOf
Example
>>>
:kind! Eval (IsSubsetOf ('Set '[]) ('Set '[0,1,2,3,4]))
Eval (IsSubsetOf ('Set '[]) ('Set '[0,1,2,3,4])) :: Bool = 'True
>>>
:kind! Eval (IsSubsetOf ('Set '[0,1]) ('Set '[0,1,2,3,4]))
Eval (IsSubsetOf ('Set '[0,1]) ('Set '[0,1,2,3,4])) :: Bool = 'True
>>>
:kind! Eval (IsSubsetOf ('Set '[0,2,1,3,4]) ('Set '[0,1,2,3,4]))
Eval (IsSubsetOf ('Set '[0,2,1,3,4]) ('Set '[0,1,2,3,4])) :: Bool = 'True
>>>
:kind! Eval (IsSubsetOf ('Set '[0,1,2,3,4,5]) ('Set '[0,1,2,3,4]))
Eval (IsSubsetOf ('Set '[0,1,2,3,4,5]) ('Set '[0,1,2,3,4])) :: Bool = 'False
data IsProperSubsetOf :: Set a -> Set a -> Exp Bool Source #
IsProperSubsetOf
Example
>>>
:kind! Eval (IsProperSubsetOf ('Set '[0,1,2,3,4]) ('Set '[0,1,2,3,4]))
Eval (IsProperSubsetOf ('Set '[0,1,2,3,4]) ('Set '[0,1,2,3,4])) :: Bool = 'False
>>>
:kind! Eval (IsProperSubsetOf ('Set '[0,2,1,3]) ('Set '[0,1,2,3,4]))
Eval (IsProperSubsetOf ('Set '[0,2,1,3]) ('Set '[0,1,2,3,4])) :: Bool = 'True
Construction
data Empty :: Exp (Set v) Source #
Empty
Example
>>>
:kind! (Eval Empty :: Set Nat)
(Eval Empty :: Set Nat) :: Set Nat = 'Set '[]
See also the other examples in this module.
data Singleton :: v -> Exp (Set v) Source #
Singleton
Example
>>>
:kind! Eval (Singleton 1)
Eval (Singleton 1) :: Set Nat = 'Set '[1]
data Insert :: v -> Set v -> Exp (Set v) Source #
Insert
Example
>>>
:kind! Eval (Insert 3 =<< FromList '[1, 2])
Eval (Insert 3 =<< FromList '[1, 2]) :: Set Nat = 'Set '[3, 1, 2]
>>>
:kind! Eval (Insert 2 =<< FromList '[1, 2])
Eval (Insert 2 =<< FromList '[1, 2]) :: Set Nat = 'Set '[1, 2]
data Delete :: v -> Set v -> Exp (Set v) Source #
Delete
Example
>>>
:kind! Eval (Delete 5 =<< FromList '[5, 3])
Eval (Delete 5 =<< FromList '[5, 3]) :: Set Nat = 'Set '[3]
>>>
:kind! Eval (Delete 7 =<< FromList '[5, 3])
Eval (Delete 7 =<< FromList '[5, 3]) :: Set Nat = 'Set '[5, 3]
data PowerSet :: Set a -> Exp (Set (Set a)) Source #
Calculate the power sets of a given type-level list. The algorithm is based on Gray codes.
Example
>>>
:kind! Eval (PowerSet =<< FromList '["a", "b", "c"])
Eval (PowerSet =<< FromList '["a", "b", "c"]) :: Set (Set Symbol) = 'Set '[ 'Set '[], 'Set '["c"], 'Set '["b"], 'Set '["b", "c"], 'Set '["a"], 'Set '["a", "b"], 'Set '["a", "c"], 'Set '["a", "b", "c"]]
>>>
:kind! Eval (PowerSet =<< FromList '[Int, Char, Maybe Int])
Eval (PowerSet =<< FromList '[Int, Char, Maybe Int]) :: Set (Set *) = 'Set '[ 'Set '[], 'Set '[Maybe Int], 'Set '[Char], 'Set '[Char, Maybe Int], 'Set '[Int], 'Set '[Int, Char], 'Set '[Int, Maybe Int], 'Set '[Int, Char, Maybe Int]]
Combine
data Union :: Set v -> Set v -> Exp (Set v) Source #
Type-level set union.
Example
>>>
:kind! Eval (Union (Eval (FromList '[5, 3])) (Eval (FromList '[5, 7])) )
Eval (Union (Eval (FromList '[5, 3])) (Eval (FromList '[5, 7])) ) :: Set Nat = 'Set '[7, 5, 3]
data Difference :: Set v -> Set v -> Exp (Set v) Source #
Type-level set difference.
Example
>>>
:kind! Eval (Difference (Eval (FromList '[3, 5])) (Eval (FromList '[5, 7])))
Eval (Difference (Eval (FromList '[3, 5])) (Eval (FromList '[5, 7]))) :: Set Nat = 'Set '[3]
Instances
type Eval (Difference (Set lst1) (Set lst2) :: Set a -> Type) Source # | |
Defined in Fcf.Data.Set |
data Intersection :: Set v -> Set v -> Exp (Set v) Source #
Type-level set intersection.
Example
>>>
:kind! Eval (Intersection (Eval (FromList '[3, 5])) (Eval (FromList '[5, 7])))
Eval (Intersection (Eval (FromList '[3, 5])) (Eval (FromList '[5, 7]))) :: Set Nat = 'Set '[5]
Instances
type Eval (Intersection (Set lst1) (Set lst2) :: Set a -> Type) Source # | |
Defined in Fcf.Data.Set |
List
data FromList :: [v] -> Exp (Set v) Source #
Use FromList to construct a Set from type-level list.
Example
>>>
:kind! Eval (FromList '[1, 2])
Eval (FromList '[1, 2]) :: Set Nat = 'Set '[1, 2]
data ToList :: Set v -> Exp [v] Source #
Get the type-level list out of the Set
.
Example
>>>
:kind! Eval (ToList =<< PowerSet =<< FromList '[1,2,3])
Eval (ToList =<< PowerSet =<< FromList '[1,2,3]) :: [Set Nat] = '[ 'Set '[], 'Set '[3], 'Set '[2], 'Set '[2, 3], 'Set '[1], 'Set '[1, 2], 'Set '[1, 3], 'Set '[1, 2, 3]]
>>>
:kind! Eval (Qsort NatListOrd =<< Map ToList =<< ToList =<< PowerSet =<< FromList '[1,2,3])
Eval (Qsort NatListOrd =<< Map ToList =<< ToList =<< PowerSet =<< FromList '[1,2,3]) :: [[Nat]] = '[ '[], '[1], '[1, 2], '[1, 2, 3], '[1, 3], '[2], '[2, 3], '[3]]