Start a Box module to describe inclusion relations between different types and get a MonadState action on the top type for any modification down there
This commit is contained in:
parent
71e62ee732
commit
a9252b129a
|
@ -17,6 +17,7 @@ cabal-version: >=1.10
|
|||
|
||||
library
|
||||
exposed-modules: PDF
|
||||
, PDF.Box
|
||||
, PDF.CMap
|
||||
, PDF.Content
|
||||
, PDF.EOL
|
||||
|
|
23
src/PDF/Box.hs
Normal file
23
src/PDF/Box.hs
Normal file
|
@ -0,0 +1,23 @@
|
|||
{-# LANGUAGE NamedFieldPuns #-}
|
||||
{-# LANGUAGE FunctionalDependencies #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE UndecidableInstances #-}
|
||||
module PDF.Box (
|
||||
Box(..)
|
||||
, modifyAt
|
||||
) where
|
||||
|
||||
import Control.Monad.State (MonadState(..))
|
||||
|
||||
class Box m i a b | m a i -> b where
|
||||
r :: i -> a -> m b
|
||||
w :: i -> a -> b -> m a
|
||||
|
||||
|
||||
modifyAt :: (MonadState a m, Box m i a b) => i -> (b -> m b) -> m ()
|
||||
modifyAt i f = do
|
||||
a <- get
|
||||
r i a >>= f >>= w i a >>= put
|
||||
|
||||
instance (Box m i a b, Box m j b c) => Box m (i, j) a c
|
Loading…
Reference in New Issue
Block a user