| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Data.TypeMergingList
Description
A Snoc List type that merges elements of the same constructor using the Semigroup instance. For example, suppose we have some data type: > data Entry = IntEntry Int | StringEntry String deriving (Eq, Data, Show) > instance Semigroup Entry where > IntEntry a <> IntEntry b = IntEntry (a + b) > StringEntry a <> StringEntry b = StringEntry (a ++ b) > _ <> b = b -- if the constructors don't match, just take the right one
Then we can do: > snoc (TypeMergingList []) (IntEntry 1) = TypeMergingList [IntEntry 1] > snoc (TypeMergingList [IntEntry 1]) (IntEntry 2) = TypeMergingList [IntEntry 3] > snoc (TypeMergingList [IntEntry 1]) (StringEntry "hello") = TypeMergingList [IntEntry 1, StringEntry "hello"] > snoc (TypeMergingList [IntEntry 1, StringEntry "hello"]) (StringEntry "world") = TypeMergingList [IntEntry 1, StringEntry "helloworld"]
Synopsis
- newtype TypeMergingList a = TypeMergingList [a]
- class Data a => DataMergeable a where
- merge :: a -> a -> a
- errorDifferentConstructors :: Data a => a -> a -> b
- getByCtor :: forall (ctor :: Symbol) s a. (Generic s, AsConstructor ctor s s a a) => TypeMergingList s -> Maybe a
- snoc :: DataMergeable a => TypeMergingList a -> a -> TypeMergingList a
- append :: DataMergeable a => TypeMergingList a -> TypeMergingList a -> TypeMergingList a
- fromList :: (DataMergeable a, Data a) => [a] -> TypeMergingList a
- toList :: TypeMergingList a -> [a]
- toVector :: TypeMergingList a -> Vector a
Documentation
newtype TypeMergingList a Source #
Constructors
| TypeMergingList [a] |
Instances
class Data a => DataMergeable a where Source #
Class of partially mergeable types.
Instances of this class may assume that the constructors of the two arguments are the same (i.e. toConstr x == toConstr y), and
are permitted to be partial if this is not the case.
Instances
| DataMergeable ClassFileAttribute Source # | |
Defined in JVM.Data.Abstract.ClassFile Methods merge :: ClassFileAttribute -> ClassFileAttribute -> ClassFileAttribute Source # | |
| DataMergeable CodeAttribute Source # | |
Defined in JVM.Data.Abstract.ClassFile.Method Methods merge :: CodeAttribute -> CodeAttribute -> CodeAttribute Source # | |
| DataMergeable CodeAttributeData Source # | |
Defined in JVM.Data.Abstract.ClassFile.Method Methods merge :: CodeAttributeData -> CodeAttributeData -> CodeAttributeData Source # | |
| DataMergeable MethodAttribute Source # | |
Defined in JVM.Data.Abstract.ClassFile.Method Methods merge :: MethodAttribute -> MethodAttribute -> MethodAttribute Source # | |
| (Data a, Semigroup a) => DataMergeable a Source # | |
Defined in Data.TypeMergingList | |
errorDifferentConstructors :: Data a => a -> a -> b Source #
getByCtor :: forall (ctor :: Symbol) s a. (Generic s, AsConstructor ctor s s a a) => TypeMergingList s -> Maybe a Source #
snoc :: DataMergeable a => TypeMergingList a -> a -> TypeMergingList a Source #
append :: DataMergeable a => TypeMergingList a -> TypeMergingList a -> TypeMergingList a Source #
fromList :: (DataMergeable a, Data a) => [a] -> TypeMergingList a Source #
toList :: TypeMergingList a -> [a] Source #
toVector :: TypeMergingList a -> Vector a Source #