Skip to content

Commit abf8a3c

Browse files
committed
Added Applicative/Monad instances for GettableStateVar
1 parent 96063a4 commit abf8a3c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Graphics/Rendering/OpenGL/GL/StateVar.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module Graphics.Rendering.OpenGL.GL.StateVar (
5757
($~), ($=!), ($~!)
5858
) where
5959

60+
import Control.Applicative ( Applicative(..) )
6061
import Data.IORef ( IORef, readIORef, writeIORef )
6162

6263
--------------------------------------------------------------------------------
@@ -83,6 +84,14 @@ instance HasGetter GettableStateVar where
8384
instance Functor GettableStateVar where
8485
fmap f (GettableStateVar g) = GettableStateVar (fmap f g)
8586

87+
instance Applicative GettableStateVar where
88+
pure = GettableStateVar . pure
89+
GettableStateVar g <*> GettableStateVar h = GettableStateVar (g <*> h)
90+
91+
instance Monad GettableStateVar where
92+
return = pure
93+
GettableStateVar g >>= h = GettableStateVar (g >>= get . h)
94+
8695
-- | Construct a 'GettableStateVar' from an IO action.
8796
makeGettableStateVar :: IO a -> GettableStateVar a
8897
makeGettableStateVar = GettableStateVar
@@ -104,6 +113,9 @@ newtype SettableStateVar a = SettableStateVar (a -> IO ())
104113
instance HasSetter SettableStateVar where
105114
($=) (SettableStateVar s) a = s a
106115

116+
-- instance Contravariant SettableStateVar where
117+
-- contramap f (SettableStateVar s) = SettableStateVar (s . f)
118+
107119
-- | Construct a 'SettableStateVar' from an IO action.
108120
makeSettableStateVar :: (a -> IO ()) -> SettableStateVar a
109121
makeSettableStateVar = SettableStateVar

0 commit comments

Comments
 (0)