Skip to content

Commit 944b071

Browse files
committed
forgot to stage some stuff
1 parent abfc7b4 commit 944b071

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

src/Data/Profunctor/Linear.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,31 @@ data Exchange a b s t = Exchange (s ->. a) (b ->. t)
159159
instance Profunctor (Exchange a b) where
160160
dimap f g (Exchange p q) = Exchange (p . f) (g . q)
161161

162+
data Top = forall x. Top x
163+
instance Show Top where
164+
show (Top _) = "something"
165+
instance Control.Functor (Const (Top, a)) where
166+
fmap f (Const (Top t, x)) = Const (Top (t,f), x)
167+
instance Monoid a => Control.Applicative (Const (Top, a)) where
168+
pure x = Const (Top x, mempty)
169+
Const (Top a, x) <*> Const (Top b, y) = Const (Top (a,b), x <> y)
170+
171+
-- TODO: pick a more sensible name for this
172+
newtype MyFunctor a b t = MyFunctor (b ->. (a, t))
173+
runMyFunctor :: MyFunctor a b t ->. b ->. (a, t)
174+
runMyFunctor (MyFunctor f) = f
175+
176+
instance Data.Functor (MyFunctor a b) where
177+
fmap f (MyFunctor g) = MyFunctor (getLA (second (LA f)) . g)
178+
instance Control.Functor (MyFunctor a b) where
179+
fmap f (MyFunctor g) = MyFunctor (thing f . g)
180+
where thing :: (c ->. d) ->. (e, c) ->. (e, d)
181+
thing k (x,y) = (x, k y)
182+
183+
instance Prelude.Semigroup Top where
184+
Top x <> Top y = Top (x,y)
185+
instance Semigroup Top where
186+
Top x <> Top y = Top (x,y)
187+
instance Prelude.Monoid Top where
188+
mempty = Top ()
189+
instance Monoid Top where

src/Prelude/Linear.hs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
{-# LANGUAGE NoImplicitPrelude #-}
77
{-# LANGUAGE RankNTypes #-}
88

9+
-- TODO: move the Functor (Either e) instance somewhere more sensible
10+
{-# OPTIONS_GHC -fno-warn-orphans #-}
11+
912
module Prelude.Linear
1013
( -- * Standard 'Prelude' function with linear types
1114
-- $linearized-prelude
@@ -18,7 +21,9 @@ module Prelude.Linear
1821
, (.)
1922
, either
2023
, maybe
21-
, forget
24+
, eta
25+
, Semigroup(..)
26+
, Monoid(..)
2227
-- * Unrestricted
2328
-- $ unrestricted
2429
, Unrestricted(..)
@@ -37,6 +42,7 @@ module Prelude.Linear
3742
, module Prelude
3843
) where
3944

45+
import Data.Semigroup.Linear
4046
import qualified Data.Functor.Linear as Data
4147
import Data.Vector.Linear (V)
4248
import qualified Data.Vector.Linear as V
@@ -56,6 +62,8 @@ import Prelude hiding
5662
, Applicative(..)
5763
, Monad(..)
5864
, Traversable(..)
65+
, Semigroup(..)
66+
, Monoid(..)
5967
)
6068
import Prelude.Linear.Internal.Simple
6169
import qualified Unsafe.Linear as Unsafe
@@ -73,10 +81,10 @@ maybe x _ Nothing = x
7381
maybe _ f (Just y) = f y
7482

7583
-- XXX: temporary
76-
-- | Convenience operator when a higher-order function expects a non-linear
77-
-- arrow but we have a linear arrow
78-
forget :: (a ->. b) ->. a -> b
79-
forget f x = f x
84+
-- | Convenience operator which does eta expansion for when a higher-order
85+
-- function expects a non-linear arrow but we have a linear arrow
86+
eta :: (a ->. b) ->. a -> b
87+
eta f x = f x
8088

8189
-- $ unrestricted
8290

0 commit comments

Comments
 (0)