Safe Haskell | None |
---|---|
Language | Haskell2010 |
- class AsFacet a s where
- class AsFacetL l a s | s l -> a where
- class AsFacetTag l a s | s l -> a where
- class AsFacetN n a s | s n -> a where
- class AsInject as ss a s | a -> as, s -> ss, s as -> a, a ss -> s where
- class AsInjectL ls as ss a s | a -> as, s -> ss, s as -> a, a ss -> s, s ls -> as where
- class AsInjectN ns as ss a s | a -> as, s -> ss, s as -> a, a ss -> s, s ns -> as where
Single type
Prism
class AsFacet a s where Source #
pick
(review
facet
) and trial
(preview
facet
) in Prism'
form.
facet
=prism'
pick
(trial'
)
let y =review
(facet
@Int) (5 :: Int) ::Which
'[Bool, Int, Char, Bool, Char] --pick
x =preview
(facet
@Int) y --trial
x `shouldBe` (Just 5)
class AsFacetL l a s | s l -> a where Source #
pickL
(review
facetL
) and trialL'
(preview
facetL'
) in Prism'
form.
let y =review
(facetL
@Bar Proxy) (Tagged (5 :: Int)) :: Which '[Tagged Foo Bool, Tagged Bar Int, Char, Bool, Char] x =preview
(facetL
@Bar Proxy) y x `shouldBe` (Just (Tagged 5))
(UniqueLabelMember * k l xs, (~) * x (KindAtLabel * k l xs)) => AsFacetL k l x (Which xs) Source # | |
class AsFacetTag l a s | s l -> a where Source #
Variation of fetchL
specialized to Tagged
which automatically tags and untags the field.
A default implementation using generics is not provided as it make GHC think that l
must be type Symbol
when l
can actually be any kind.
Create instances of AsFacetTag'
using Data.Generics.Sum.Constructors as follows:
instance AsConstructor' l Foo Foo a a => AsFacetTag l a Foo where
facetTag = _Ctor
l
@
(UniqueLabelMember * k l xs, (~) * (Tagged k l x) (KindAtLabel * k l xs)) => AsFacetTag k l x (Which xs) Source # | |
Multiple types
Prism
class AsInject as ss a s | a -> as, s -> ss, s as -> a, a ss -> s where Source #
diversify
(review
inject
) and reinterpret'
(preview
inject
) in Prism'
form.
let x =pick
(5 :: Int) ::Which
'[String, Int] y =review
(inject
@_ @[Bool, Int, Char, String]) x --diversify
y `shouldBe` pick (5 :: Int) ::Which
'[Bool, Int, Char, String] let y' =preview
(inject
@[String, Int]) y --reinterpret
y' `shouldBe` Just (pick (5 :: Int)) :: Maybe (Which
'[String, Int])
class AsInjectL ls as ss a s | a -> as, s -> ss, s as -> a, a ss -> s, s ls -> as where Source #
diversifyL
(review
injectL
) and reinterpretL'
(preview
injectL
) in Prism'
form.
let t =pick
@[Tagged Bar Int, Tagged Foo Bool, Tagged Hi Char, Tagged Bye Bool] (5 :: Tagged Bar Int) b =pick
@'[Tagged Foo Bool, Tagged Bar Int] (5 :: Tagged Bar Int) t' =review
(injectL
@[Foo, Bar] @_ @[Tagged Bar Int, Tagged Foo Bool, Tagged Hi Char, Tagged Bye Bool] Proxy) b b' =preview
(injectL
@[Foo, Bar] Proxy) t' t `shouldBe` t' b' `shouldBe` Just b
(Diversify branch tree, Reinterpret' branch tree, (~) [Type] branch (KindsAtLabels Type k ls tree), UniqueLabels Type k ls tree, IsDistinct k ls) => AsInjectL [Type] [k] ls branch tree (Which branch) (Which tree) Source # | |
class AsInjectN ns as ss a s | a -> as, s -> ss, s as -> a, a ss -> s, s ns -> as where Source #
diversifyN
(review
injectN
) and reinterpretN'
(preview
injectN
) in Prism'
form.
let x =pick
(5 :: Int) ::Which
'[String, Int] y =review
(injectN @[3, 1] @_ @[Bool, Int, Char, String] Proxy) x --diversifyN
y `shouldBe` pick (5 :: Int) ::Which
'[Bool, Int, Char, String] let y' =preview
(injectN
@[3, 1] @[String, Int] Proxy) y --reinterpertN'
y' `shouldBe` Just (pick
(5 :: Int)) :: Maybe (Which
'[String, Int])
(DiversifyN ns branch tree, ReinterpretN' ns branch tree) => AsInjectN [Type] ns branch tree (Which branch) (Which tree) Source # | |