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:
Tissevert 2020-02-23 22:24:59 +01:00
parent 71e62ee732
commit a9252b129a
2 changed files with 24 additions and 0 deletions

View File

@ -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
View 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