multistate 0.7.0.0 → 0.7.1.1
raw patch · 17 files changed
+198/−29 lines, 17 filesdep ~basedep ~hspecdep ~transformersPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base, hspec, transformers
API changes (from Hackage documentation)
+ Control.Monad.Trans.MultiRWS: withoutMultiReader :: Monad m => MultiRWST rs w s m a -> MultiRWST (r : rs) w s m a
+ Control.Monad.Trans.MultiRWS: withoutMultiState :: Monad m => MultiRWST r w ss m a -> MultiRWST r w (s : ss) m a
+ Control.Monad.Trans.MultiRWS.Lazy: withoutMultiReader :: Monad m => MultiRWST rs w s m a -> MultiRWST (r : rs) w s m a
+ Control.Monad.Trans.MultiRWS.Lazy: withoutMultiState :: Monad m => MultiRWST r w ss m a -> MultiRWST r w (s : ss) m a
+ Control.Monad.Trans.MultiRWS.Strict: withoutMultiReader :: Monad m => MultiRWST rs w s m a -> MultiRWST (r : rs) w s m a
+ Control.Monad.Trans.MultiRWS.Strict: withoutMultiState :: Monad m => MultiRWST r w ss m a -> MultiRWST r w (s : ss) m a
+ Control.Monad.Trans.MultiReader: withoutMultiReader :: Monad m => MultiReaderT rs m a -> MultiReaderT (r : rs) m a
+ Control.Monad.Trans.MultiReader.Lazy: withoutMultiReader :: Monad m => MultiReaderT rs m a -> MultiReaderT (r : rs) m a
+ Control.Monad.Trans.MultiReader.Strict: withoutMultiReader :: Monad m => MultiReaderT rs m a -> MultiReaderT (r : rs) m a
+ Control.Monad.Trans.MultiState: withoutMultiState :: (Functor m, Monad m) => MultiStateT ss m a -> MultiStateT (s : ss) m a
+ Control.Monad.Trans.MultiState.Lazy: withoutMultiState :: (Functor m, Monad m) => MultiStateT ss m a -> MultiStateT (s : ss) m a
+ Control.Monad.Trans.MultiState.Strict: withoutMultiState :: (Functor m, Monad m) => MultiStateT ss m a -> MultiStateT (s : ss) m a
Files
- README.md +11/−7
- changelog.md +10/−2
- multistate.cabal +18/−13
- src/Control/Monad/Trans/MultiRWS.hs +3/−0
- src/Control/Monad/Trans/MultiRWS/Lazy.hs +30/−0
- src/Control/Monad/Trans/MultiRWS/Strict.hs +30/−0
- src/Control/Monad/Trans/MultiReader.hs +4/−2
- src/Control/Monad/Trans/MultiReader/Lazy.hs +15/−2
- src/Control/Monad/Trans/MultiReader/Strict.hs +15/−2
- src/Control/Monad/Trans/MultiState.hs +2/−0
- src/Control/Monad/Trans/MultiState/Lazy.hs +15/−0
- src/Control/Monad/Trans/MultiState/Strict.hs +16/−1
- src/Control/Monad/Trans/MultiWriter/Lazy.hs +5/−0
- src/Control/Monad/Trans/MultiWriter/Strict.hs +5/−0
- src/Data/HList/ContainsType.hs +6/−0
- src/Data/HList/HList.hs +8/−0
- test/Test.hs +5/−0
README.md view
@@ -20,10 +20,10 @@ ~~~~ simpleExample :: IO ()-simpleExample = evalMultiStateT -- start with an empty state,+simpleExample = runMultiStateTNil_ -- start with an empty state, -- i.e. :: MultiStateT '[] IO- $ withMultiState 'H' -- "adding" a char to the state- $ withMultiState "ello, World!" -- and a string+ $ withMultiStateA 'H' -- "adding" a char to the state+ $ withMultiStateA "ello, World!" -- and a string $ do -- so: -- the monad here is MultiStateT '[String, Char] IO let combinedPrint = do -- no type signature necessary@@ -101,16 +101,18 @@ /-------------------------------------------------------\ | withState withState .. withState v StateT '[s, ..] m --------> StateT '[..] m --------> .. --------> StateT '[] m+ | <-------- |+ | (withoutState) | | | | | | runStateT runStateTNil | \--------------------> m .. <---------------------------/ ~~~~ -Specific functions are+Specific functions are (constraints omitted): ~~~~-runMultiStateT = runStateTAS+runMultiStateT = runMultiStateTAS runMultiStateTA :: HList s -> MultiStateT s m a -> m a runMultiStateTAS :: HList s -> MultiStateT s m a -> m (a, s) runMultiStateTSA :: HList s -> MultiStateT s m a -> m (s, a)@@ -120,19 +122,21 @@ runMultiStateTNil :: MultiStateT '[] m a -> m a runMultiStateTNil_ :: MultiStateT '[] m a -> m () -withMultiState = withStateAS+withMultiState = withMultiStateAS withMultiStateA :: s -> MultiStateT (s ': ss) m a -> MultiStateT ss m a withMultiStateAS :: s -> MultiStateT (s ': ss) m a -> MultiStateT ss m (a, s) withMultiStateSA :: s -> MultiStateT (s ': ss) m a -> MultiStateT ss m (s, a) withMultiStateS :: s -> MultiStateT (s ': ss) m a -> MultiStateT ss m s withMultiState_ :: s -> MultiStateT (s ': ss) m a -> MultiStateT ss m () -withMultiStates = withStatesAS+withMultiStates = withMultiStatesAS withMultiStatesAS :: HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (a, HList s1) withMultiStatesSA :: HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (HList s1, a) withMultiStatesA :: HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m a withMultiStatesS :: HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m (HList s1) withMultiStates_ :: HList s1 -> MultiStateT (Append s1 s2) m a -> MultiStateT s2 m ()++withoutMultiState :: MultiStateT ss m a -> MultiStateT (s ': ss) m a ~~~~ ## Known Deficits
changelog.md view
@@ -1,5 +1,13 @@ # Changelog for [`multistate` package](https://hackage.haskell.org/package/multistate) +## 0.7.1.1 *May 2016*++ * Adapt for ghc-8++## 0.7.1.0 *March 2016*++ * Add new method `withoutMultiFoo`, inverse of `withMultiFoo`+ ## 0.7.0.0 *February 2016* * Add instances:@@ -60,7 +68,7 @@ * Deprecate previous modules -## 0.3.0.0 *Januar 2015*+## 0.3.0.0 *January 2015* * Add `MultiWriter` @@ -68,7 +76,7 @@ * support ghc-7.10 -## 0.2.0.0 *Januar 2015*+## 0.2.0.0 *January 2015* * Start using DataKinds and TypeOperators to make the HList representation more readable. The translation roughly is:
multistate.cabal view
@@ -1,5 +1,5 @@ Name: multistate-Version: 0.7.0.0+Version: 0.7.1.1 Cabal-Version: >= 1.10 Build-Type: Simple license: BSD3@@ -11,7 +11,7 @@ Bug-reports: https://github.com/lspitzner/multistate/issues Stability: Experimental category: Control-tested-with: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.1+tested-with: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1 Synopsis: like mtl's ReaderT / WriterT / StateT, but more than one contained value/type.@@ -26,9 +26,6 @@ . See the <https://github.com/lspitzner/multistate README> for a longer description.- .- The latest published version contains some breaking changes.- Please complain if this causes problems (for future consideration). extra-source-files: README.md@@ -68,26 +65,34 @@ Control.Monad.Trans.MultiRWS.Strict other-modules: build-depends:- base >= 4.6 && <4.9,+ base >= 4.6 && <4.10, mtl >= 2.1 && <2.3,- transformers >= 0.3 && <0.5,+ transformers >= 0.3 && <0.6, tagged >= 0.7 && <0.9, transformers-base <0.5,- monad-control <1.1+ monad-control >= 1.0 && <1.1 default-extensions: GADTs TypeFamilies MultiParamTypeClasses FunctionalDependencies FlexibleInstances- OverlappingInstances UndecidableInstances TypeOperators DataKinds+ if impl(ghc < 7.10) {+ default-extensions:+ OverlappingInstances+ } ghc-options: { -Wall -fno-warn-unused-imports }+ if impl(ghc > 8.0) {+ ghc-options: {+ -fno-warn-redundant-constraints+ }+ } hs-source-dirs: src } @@ -99,8 +104,8 @@ -- no version constraints necessary, because they are already -- given by library multistate,- base <4.9,- transformers <0.5,+ base <4.10,+ transformers <0.6, hspec <2.3 ghc-options: -Wall main-is: Test.hs@@ -116,9 +121,9 @@ -- no version constraints necessary, because they are already -- given by library multistate,- base <4.9,+ base <4.10, mtl <2.3,- transformers <0.5+ transformers <0.6 } else { buildable: False }
src/Control/Monad/Trans/MultiRWS.hs view
@@ -42,6 +42,9 @@ , withMultiStatesA , withMultiStatesS , withMultiStates_+ -- * without-functions (reducing an RWST; inverse of with)+ , withoutMultiReader+ , withoutMultiState -- * inflate-functions (run simple transformer in MultiRWST) , inflateReader , inflateMultiReader
src/Control/Monad/Trans/MultiRWS/Lazy.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-}@@ -46,6 +47,9 @@ , withMultiStatesA , withMultiStatesS , withMultiStates_+ -- * without-functions (reducing an RWST; inverse of with)+ , withoutMultiReader+ , withoutMultiState -- * inflate-functions (run simple transformer in MultiRWST) , inflateReader , inflateMultiReader@@ -136,17 +140,29 @@ instance MonadTrans (MultiRWST r w s) where lift = MultiRWST . lift +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} (Monad m, ContainsType a r)+#else instance (Monad m, ContainsType a r)+#endif => MonadMultiReader a (MultiRWST r w s m) where mAsk = MultiRWST $ liftM (\(r,_,_) -> getHListElem r) get +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} (Monad m, ContainsType a w, Monoid a)+#else instance (Monad m, ContainsType a w, Monoid a)+#endif => MonadMultiWriter a (MultiRWST r w s m) where mTell v = MultiRWST $ do ~(r,w,s) <- get put $ (r, setHListElem (getHListElem w `mappend` v) w, s) +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} (Monad m, ContainsType a s)+#else instance (Monad m, ContainsType a s)+#endif => MonadMultiState a (MultiRWST r w s m) where mSet v = MultiRWST $ do ~(r,w,s) <- get@@ -360,6 +376,20 @@ return (x' :+: xs') withMultiStates_ HNil = void withMultiStates_ (x :+: xs) = withMultiStates_ xs . withMultiState_ x++withoutMultiReader :: Monad m => MultiRWST rs w s m a -> MultiRWST (r ': rs) w s m a+withoutMultiReader k = MultiRWST $ do+ (rs@(_ :+: rr), w, s) <- get+ ~(a, ~(_, w', s')) <- lift $ runStateT (runMultiRWSTRaw k) (rr, w, s)+ put (rs, w', s')+ return a++withoutMultiState :: Monad m => MultiRWST r w ss m a -> MultiRWST r w (s ': ss) m a+withoutMultiState k = MultiRWST $ do+ (r, w, s :+: sr) <- get+ ~(a, ~(_, w', s')) <- lift $ runStateT (runMultiRWSTRaw k) (r, w, sr)+ put (r, w', s :+: s')+ return a inflateReader :: (Monad m, ContainsType r rs) => ReaderT r m a
src/Control/Monad/Trans/MultiRWS/Strict.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-}@@ -46,6 +47,9 @@ , withMultiStatesA , withMultiStatesS , withMultiStates_+ -- * without-functions (reducing an RWST; inverse of with)+ , withoutMultiReader+ , withoutMultiState -- * inflate-functions (run simple transformer in MultiRWST) , inflateReader , inflateMultiReader@@ -136,17 +140,29 @@ instance MonadTrans (MultiRWST r w s) where lift = MultiRWST . lift +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} (Monad m, ContainsType a r)+#else instance (Monad m, ContainsType a r)+#endif => MonadMultiReader a (MultiRWST r w s m) where mAsk = MultiRWST $ liftM (\(r,_,_) -> getHListElem r) get +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} (Monad m, ContainsType a w, Monoid a)+#else instance (Monad m, ContainsType a w, Monoid a)+#endif => MonadMultiWriter a (MultiRWST r w s m) where mTell v = MultiRWST $ do (r,w,s) <- get put $ (r, setHListElem (getHListElem w `mappend` v) w, s) +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} (Monad m, ContainsType a s)+#else instance (Monad m, ContainsType a s)+#endif => MonadMultiState a (MultiRWST r w s m) where mSet v = MultiRWST $ do (r,w,s) <- get@@ -360,6 +376,20 @@ return (x' :+: xs') withMultiStates_ HNil = void withMultiStates_ (x :+: xs) = withMultiStates_ xs . withMultiState_ x++withoutMultiReader :: Monad m => MultiRWST rs w s m a -> MultiRWST (r ': rs) w s m a+withoutMultiReader k = MultiRWST $ do+ (rs@(_ :+: rr), w, s) <- get+ (a, (_, w', s')) <- lift $ runStateT (runMultiRWSTRaw k) (rr, w, s)+ put (rs, w', s')+ return a++withoutMultiState :: Monad m => MultiRWST r w ss m a -> MultiRWST r w (s ': ss) m a+withoutMultiState k = MultiRWST $ do+ (r, w, s :+: sr) <- get+ (a, (_, w', s')) <- lift $ runStateT (runMultiRWSTRaw k) (r, w, sr)+ put (r, w', s :+: s')+ return a inflateReader :: (Monad m, ContainsType r rs) => ReaderT r m a
src/Control/Monad/Trans/MultiReader.hs view
@@ -12,12 +12,14 @@ , runMultiReaderT_ , runMultiReaderTNil , runMultiReaderTNil_- -- * with-functions (single Reader)+ -- * with-functions (single reader) , withMultiReader , withMultiReader_- -- * with-functions (multiple Readers)+ -- * with-functions (multiple readers) , withMultiReaders , withMultiReaders_+ -- * without-function (single reader)+ , withoutMultiReader -- * inflate-function (run ReaderT in MultiReaderT) , inflateReader -- * other functions
src/Control/Monad/Trans/MultiReader/Lazy.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ -- | The multi-valued version of mtl's Reader / ReaderT module Control.Monad.Trans.MultiReader.Lazy (@@ -12,12 +14,14 @@ , runMultiReaderT_ , runMultiReaderTNil , runMultiReaderTNil_- -- * with-functions (single Reader)+ -- * with-functions (single reader) , withMultiReader , withMultiReader_- -- * with-functions (multiple Readers)+ -- * with-functions (multiple readers) , withMultiReaders , withMultiReaders_+ -- * without-function (single reader)+ , withoutMultiReader -- * inflate-function (run ReaderT in MultiReaderT) , inflateReader -- * other functions@@ -115,7 +119,11 @@ instance MonadTrans (MultiReaderT x) where lift = MultiReaderT . lift +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} (Monad m, ContainsType a c)+#else instance (Monad m, ContainsType a c)+#endif => MonadMultiReader a (MultiReaderT c m) where mAsk = MultiReaderT $ liftM getHListElem get @@ -166,6 +174,11 @@ withMultiReaders (x :+: xs) = withMultiReaders xs . withMultiReader x withMultiReaders_ HNil = liftM (const ()) withMultiReaders_ (x :+: xs) = withMultiReaders_ xs . withMultiReader_ x++withoutMultiReader :: Monad m => MultiReaderT rs m a -> MultiReaderT (r ': rs) m a+withoutMultiReader k = MultiReaderT $ do+ _ :+: rr <- get+ lift $ runMultiReaderT rr k inflateReader :: (Monad m, ContainsType r rs) => ReaderT r m a
src/Control/Monad/Trans/MultiReader/Strict.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ -- | The multi-valued version of mtl's Reader / ReaderT module Control.Monad.Trans.MultiReader.Strict (@@ -12,12 +14,14 @@ , runMultiReaderT_ , runMultiReaderTNil , runMultiReaderTNil_- -- * with-functions (single Reader)+ -- * with-functions (single reader) , withMultiReader , withMultiReader_- -- * with-functions (multiple Readers)+ -- * with-functions (multiple readers) , withMultiReaders , withMultiReaders_+ -- * without-function (single reader)+ , withoutMultiReader -- * inflate-function (run ReaderT in MultiReaderT) , inflateReader -- * other functions@@ -115,7 +119,11 @@ instance MonadTrans (MultiReaderT x) where lift = MultiReaderT . lift +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} (Monad m, ContainsType a c)+#else instance (Monad m, ContainsType a c)+#endif => MonadMultiReader a (MultiReaderT c m) where mAsk = MultiReaderT $ liftM getHListElem get @@ -166,6 +174,11 @@ withMultiReaders (x :+: xs) = withMultiReaders xs . withMultiReader x withMultiReaders_ HNil = liftM (const ()) withMultiReaders_ (x :+: xs) = withMultiReaders_ xs . withMultiReader_ x++withoutMultiReader :: Monad m => MultiReaderT rs m a -> MultiReaderT (r ': rs) m a+withoutMultiReader k = MultiReaderT $ do+ _ :+: rr <- get+ lift $ runMultiReaderT rr k inflateReader :: (Monad m, ContainsType r rs) => ReaderT r m a
src/Control/Monad/Trans/MultiState.hs view
@@ -31,6 +31,8 @@ , withMultiStatesA , withMultiStatesS , withMultiStates_+ -- * without-function (single state)+ , withoutMultiState -- * inflate-functions (run single state in multiple states) , inflateState , inflateReader
src/Control/Monad/Trans/MultiState/Lazy.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ -- | The multi-valued version of mtl's State / StateT module Control.Monad.Trans.MultiState.Lazy (@@ -30,6 +32,8 @@ , withMultiStatesA , withMultiStatesS , withMultiStates_+ -- * without-function (single state)+ , withoutMultiState -- * inflate-functions (run single state in multiple states) , inflateState , inflateReader@@ -133,7 +137,11 @@ instance MonadTrans (MultiStateT x) where lift = MultiStateT . lift +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} (Monad m, ContainsType a c)+#else instance (Monad m, ContainsType a c)+#endif => MonadMultiState a (MultiStateT c m) where mSet v = MultiStateT $ get >>= put . setHListElem v mGet = MultiStateT $ liftM getHListElem get@@ -221,6 +229,13 @@ . withMultiStateS x withMultiStates_ HNil = liftM (const ()) withMultiStates_ (x :+: xs) = withMultiStates_ xs . withMultiState_ x++withoutMultiState :: (Functor m, Monad m) => MultiStateT ss m a -> MultiStateT (s ': ss) m a+withoutMultiState k = MultiStateT $ do+ s :+: sr <- get+ ~(a, sr') <- lift $ runMultiStateT sr k+ put (s :+: sr')+ return a inflateState :: (Monad m, ContainsType s ss) => StateT s m a
src/Control/Monad/Trans/MultiState/Strict.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ -- | The multi-valued version of mtl's State / StateT module Control.Monad.Trans.MultiState.Strict (@@ -30,6 +32,8 @@ , withMultiStatesA , withMultiStatesS , withMultiStates_+ -- * without-function (single state)+ , withoutMultiState -- * inflate-functions (run single state in multiple states) , inflateState , inflateReader@@ -131,7 +135,11 @@ instance MonadTrans (MultiStateT x) where lift = MultiStateT . lift +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} (Monad m, ContainsType a c)+#else instance (Monad m, ContainsType a c)+#endif => MonadMultiState a (MultiStateT c m) where mSet v = MultiStateT $ get >>= put . setHListElem v mGet = MultiStateT $ liftM getHListElem get@@ -189,7 +197,7 @@ withMultiState = withMultiStateAS withMultiStateAS x k = MultiStateT $ do s <- get- ~(a, s') <- lift $ runStateT (runMultiStateTRaw k) (x :+: s)+ (a, s') <- lift $ runStateT (runMultiStateTRaw k) (x :+: s) case s' of x' :+: sr' -> do put sr'; return (a, x') withMultiStateSA s k = (\(a,b) -> (b,a)) `liftM` withMultiStateAS s k withMultiStateA s k = fst `liftM` withMultiStateAS s k@@ -219,6 +227,13 @@ . withMultiStateS x withMultiStates_ HNil = liftM (const ()) withMultiStates_ (x :+: xs) = withMultiStates_ xs . withMultiState_ x++withoutMultiState :: (Functor m, Monad m) => MultiStateT ss m a -> MultiStateT (s ': ss) m a+withoutMultiState k = MultiStateT $ do+ s :+: sr <- get+ (a, sr') <- lift $ runMultiStateT sr k+ put (s :+: sr')+ return a inflateState :: (Monad m, ContainsType s ss) => StateT s m a
src/Control/Monad/Trans/MultiWriter/Lazy.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-}@@ -125,7 +126,11 @@ instance MonadTrans (MultiWriterT x) where lift = MultiWriterT . lift +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} (Monad m, ContainsType a c, Monoid a)+#else instance (Monad m, ContainsType a c, Monoid a)+#endif => MonadMultiWriter a (MultiWriterT c m) where mTell v = MultiWriterT $ do x <- get
src/Control/Monad/Trans/MultiWriter/Strict.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-}@@ -125,7 +126,11 @@ instance MonadTrans (MultiWriterT x) where lift = MultiWriterT . lift +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} (Monad m, ContainsType a c, Monoid a)+#else instance (Monad m, ContainsType a c, Monoid a)+#endif => MonadMultiWriter a (MultiWriterT c m) where mTell v = MultiWriterT $ do x <- get
src/Data/HList/ContainsType.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE CPP #-}+ -- | Class to provide type-driven access to elements of a HList module Data.HList.ContainsType ( ContainsType(..)@@ -14,7 +16,11 @@ setHListElem :: a -> HList c -> HList c getHListElem :: HList c -> a +#if MIN_VERSION_base(4,8,0)+instance {-# OVERLAPPING #-} ContainsType a (a ': xs) where+#else instance ContainsType a (a ': xs) where+#endif setHListElem a xs = a :+: case xs of (_ :+: xr) -> xr getHListElem (x :+: _) = x
src/Data/HList/HList.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DataKinds #-}@@ -62,6 +63,9 @@ x1 :+: xr1 == x2 :+: xr2 = x1==x2 && xr1==xr2 x1 :+: xr1 /= x2 :+: xr2 = x1/=x2 || xr1/=xr2 +-- cannot use the closed variant because of ghc-7.8.4.+-- (was not investigated more closely; there simply+-- is some syntax error for code which works fine with ghc-7.10.) type family Append (l1::[*]) (l2::[*]) :: [*] type instance Append '[] l2 = l2 type instance Append (car1 ': cdr2) l2 = car1 ': Append cdr2 l2@@ -79,7 +83,11 @@ hSplit l = (HNil, l) instance HInit l1 => HInit (x ': l1) where hInit p (x :+: xs) = x :+: hInit p xs+#if !MIN_VERSION_base(4,9,0) hInit _ _ = error "cannot happen" -- see ghc trac #3927+#endif hSplit (x :+: xs) = let (l1, l2) = hSplit xs in (x :+: l1, l2)+#if !MIN_VERSION_base(4,9,0) hSplit _ = error "cannot happen"+#endif
test/Test.hs view
@@ -1,7 +1,9 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-}+{-# OPTIONS_GHC -fno-warn-unused-imports #-} module Main where @@ -196,6 +198,9 @@ l :: (Int, Bool) l = case runIdentity $ MS.runMultiStateTS ([] :+: [] :+: HNil) action of (x :+: y :+: _) -> (head x, head y)+#if !MIN_VERSION_base(4,9,0)+ _ -> error "some ghc versions think that above is not exhaustive."+#endif action :: MS.MultiStateT '[[Int], [Bool]] Identity () action = do action