pointless-lenses 0.0.1 → 0.0.2
raw patch · 4 files changed
+47/−2 lines, 4 files
Files
- pointless-lenses.cabal +1/−1
- src/Generics/Pointless/Lenses/Combinators.hs +17/−1
- src/Generics/Pointless/Lenses/Examples/Examples.hs +27/−0
- src/Generics/Pointless/Lenses/RecursionPatterns.hs +2/−0
pointless-lenses.cabal view
@@ -1,5 +1,5 @@ Name: pointless-lenses-Version: 0.0.1+Version: 0.0.2 License: BSD3 License-file: LICENSE Author: Alcino Cunha <alcino@di.uminho.pt>, Hugo Pacheco <hpacheco@di.uminho.pt>
src/Generics/Pointless/Lenses/Combinators.hs view
@@ -19,9 +19,26 @@ import Generics.Pointless.Lenses import Generics.Pointless.Combinators+import Generics.Pointless.Functors -- * Point-free lens combinators +-- | Function application is a lens.+ap_lns :: Eq a => a -> Lens ((a -> b),a) b+ap_lns a = Lens get' put' create'+ where get' = app+ put' (b,(f,a)) = (\x -> if x==a then b else f x,a)+ create' = const /\ const a++-- | Predicate application is a lens.+infix 0 ?<+(?<) :: Eq a => Lens (a -> Bool,a) (Either a a)+(?<) = Lens get' put' create'+ where get' = (snd -|- snd) . distl . (out . app /\ snd)+ put' = ((orf \/ andf) . distl . (eqneq >< fst)) /\ ((id \/ id) . fst)+ create' = (curry eq /\ id) \/ (const (inn . inr . bang) /\ id)+ eqneq = curry eq -|- curry neq+ -- | The right exponentiation combinator as a lens. -- Applies a lens to the domain of a function. rexp_lns :: Lens b c -> Lens (a -> b) (a -> c)@@ -178,4 +195,3 @@ -- | The @coassocr@ point-free combinator. coassocr_lns :: Lens (Either (Either a b) c) (Either a (Either b c)) coassocr_lns = Lens coassocr (coassocl . fst) coassocl-
src/Generics/Pointless/Lenses/Examples/Examples.hs view
@@ -42,6 +42,33 @@ filter_lns :: Lens [Either a b] [a] filter_lns = cata_lns _L ((inn_lns .\/< snd_lns _L) .< coassocl_lns .< (id_lns -|-< distl_lns)) +-- | Binary list concatenation.+cat_lns :: Lens ([a],[a]) [a]+cat_lns = Lens get' put' create'+ where get' = uncurry (++)+ put' (l,(e,d)) = splitAt (length e) l+ create' l = splitAt (length l `div` 2) l++data Tree a = Empty | Node a (Tree a) (Tree a) deriving (Eq,Show)++type instance BF Tree = BConst One :+| (BPar :*| (BId :*| BId))++type instance PF (Tree a) = Const One :+: (Const a :*: (Id :*: Id))++instance Mu (Tree a) where+ inn (Left _) = Empty+ inn (Right (a,(b,c))) = Node a b c+ out Empty = Left _L+ out (Node a b c) = Right (a,(b,c))++-- | Flatten a tree.+flatten_lns :: Lens (Tree a) [a]+flatten_lns = cata_lns _L (inn_lns .< (id_lns -|-< id_lns ><< cat_lns))++-- | List concatenation.+concat_lns :: Lens [[a]] [a]+concat_lns = cata_lns _L (inn_lns .< (((id_lns .\/< id_lns) -|-< id_lns) .< coassocl_lns .< (id_lns -|-< out_lns .< cat_lns)))+ -- | List mapping lens. map_lns :: Lens c a -> Lens [c] [a] map_lns f = nat_lns _L (\x -> id_lns -|-< f ><< id_lns)
src/Generics/Pointless/Lenses/RecursionPatterns.hs view
@@ -28,9 +28,11 @@ import Generics.Pointless.Lenses import Generics.Pointless.Lenses.Combinators +-- | The @inn@ point-free combinator. inn_lns :: Mu a => Lens (F a a) a inn_lns = Lens inn (out . fst) out +-- | The @out@ point-free combinator. out_lns :: Mu a => Lens a (F a a) out_lns = Lens out (inn . fst) inn