Skip to content

Commit dad3c10

Browse files
committed
Top monoid and misc fixes
[skip ci]
1 parent 42b5571 commit dad3c10

File tree

7 files changed

+25
-17
lines changed

7 files changed

+25
-17
lines changed

src/Control/Optics/Linear/Internal.hs

+5-7
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ module Control.Optics.Linear.Internal
2424
, _Just, _Nothing
2525
, ptraversed, dtraversed
2626
, both, both'
27-
, get', gets', set'
2827
-- * Using optics
2928
, get, set, gets
29+
, get', gets', set', set''
3030
, match, match', build
3131
, preview
3232
, over, over'
@@ -42,15 +42,13 @@ module Control.Optics.Linear.Internal
4242
import qualified Control.Arrow as NonLinear
4343
import qualified Data.Bifunctor.Linear as Bifunctor
4444
import Data.Bifunctor.Linear (SymmetricMonoidal)
45-
import Data.Monoid
45+
import Data.Monoid (First(..), Sum(..))
4646
import Data.Functor.Const
4747
import Data.Functor.Linear
4848
import Data.Profunctor.Linear
49-
import Data.Functor.Linear
5049
import qualified Data.Profunctor.Kleisli.Linear as Linear
5150
import Data.Void
52-
import Prelude.Linear hiding ((<$>))
53-
-- ^ XXX: not entirely sure why the hiding is necessary here...
51+
import Prelude.Linear
5452
import qualified Prelude as P
5553

5654
-- TODO: documentation in this module
@@ -159,8 +157,8 @@ get l = gets l P.id
159157
gets :: Optic_ (NonLinear.Kleisli (Const r)) a b s t -> (a -> r) -> s -> r
160158
gets (Optical l) f s = getConst' (NonLinear.runKleisli (l (NonLinear.Kleisli (Const P.. f))) s)
161159

162-
preview :: Optic_ (NonLinear.Kleisli (Const (Maybe (First a)))) a b s t -> s -> Maybe a
163-
preview (Optical l) s = getFirst P.<$> (getConst (NonLinear.runKleisli (l (NonLinear.Kleisli (\a -> Const (Just (First a))))) s))
160+
preview :: Optic_ (NonLinear.Kleisli (Const (First a))) a b s t -> s -> Maybe a
161+
preview (Optical l) s = getFirst (getConst (NonLinear.runKleisli (l (NonLinear.Kleisli (\a -> Const (First (Just a))))) s))
164162

165163
get' :: Optic_ (Linear.Kleisli (Const (Top, a))) a b s t -> s ->. (Top, a)
166164
get' l = gets' l id

src/Data/Monoid/Linear.hs

+14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
44
{-# LANGUAGE LinearTypes #-}
55
{-# LANGUAGE NoImplicitPrelude #-}
6+
{-# LANGUAGE ExistentialQuantification #-}
67
{-# LANGUAGE StandaloneDeriving #-}
78

89
-- | = The linear monoid hierarchy
@@ -14,6 +15,7 @@ module Data.Monoid.Linear
1415
, Monoid(..)
1516
, Endo(..), appEndo
1617
, NonLinear(..)
18+
, Top, throw
1719
, module Data.Semigroup
1820
)
1921
where
@@ -80,3 +82,15 @@ newtype NonLinear a = NonLinear a
8082

8183
instance Semigroup a => Prelude.Semigroup (NonLinear a) where
8284
NonLinear a <> NonLinear b = NonLinear (a <> b)
85+
86+
data Top = forall x. Top x
87+
throw :: x ->. Top
88+
throw = Top
89+
90+
instance Prelude.Semigroup Top where
91+
Top x <> Top y = Top (x,y)
92+
instance Semigroup Top where
93+
Top x <> Top y = Top (x,y)
94+
instance Prelude.Monoid Top where
95+
mempty = Top ()
96+
instance Monoid Top where

src/Data/Profunctor/Kleisli/Linear.hs

-8
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ instance Control.Applicative f => DWandering (Kleisli f) where
4949
-- profunctorial properties still hold in this weaker setting.
5050
-- However stronger requirements on `f` are needed for profunctorial
5151
-- strength, so we have fewer instances.
52-
--
53-
-- Category theoretic remark: duality doesn't work in the obvious way, since
54-
-- (,) isn't the categorical product. Instead, we have a product (&), called
55-
-- "With", defined by
56-
-- > type With a b = forall r. Either (a ->. r) (b ->. r) ->. r
57-
-- which satisfies the universal property of the product of `a` and `b`.
58-
-- CoKleisli arrows are strong with respect to this monoidal structure,
59-
-- although this might not be useful...
6052
newtype CoKleisli w a b = CoKleisli { runCoKleisli :: w a ->. b }
6153

6254
instance Data.Functor f => Profunctor (CoKleisli f) where

src/Data/Profunctor/Linear.hs

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ instance Strong Either Void LinearArrow where
9999
first (LA f) = LA $ either (Left . f) Right
100100
second (LA g) = LA $ either Left (Right . g)
101101

102+
instance DWandering LinearArrow where
103+
dwander (LA f) = LA (Data.fmap f)
104+
102105
instance Profunctor (->) where
103106
dimap f g h x = g (h (f x))
104107
instance Strong (,) () (->) where

src/Foreign/Marshal/Pure.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import Foreign.Marshal.Utils
6060
import Foreign.Ptr
6161
import Foreign.Storable
6262
import Foreign.Storable.Tuple ()
63-
import Prelude (($), return, (<*>))
63+
import Prelude (($), return, (<*>), (<$>))
6464
import Prelude.Linear hiding (($))
6565
import System.IO.Unsafe
6666
import qualified Unsafe.Linear as Unsafe

src/Prelude/Linear.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import Prelude hiding
5353
, foldr
5454
, maybe
5555
, (.)
56-
, Functor(..)
56+
, Functor(..), (<$>)
5757
, Applicative(..)
5858
, Monad(..)
5959
, Traversable(..)

src/System/IO/Linear.hs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import qualified Control.Monad.Linear as Control
4141
import qualified Data.Functor.Linear as Data
4242
import GHC.Exts (State#, RealWorld)
4343
import Prelude.Linear hiding (IO)
44+
import Prelude ((<$>))
4445
import qualified Unsafe.Linear as Unsafe
4546
import qualified System.IO as System
4647

0 commit comments

Comments
 (0)