monad-skeleton 0 → 0.1
raw patch · 2 files changed
+20/−2 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Monad.Skeleton: hoistMonadView :: (forall x. s x -> t x) -> (m a -> n a) -> MonadView s m a -> MonadView t n a
+ Control.Monad.Skeleton: hoistSkeleton :: (forall x. s x -> t x) -> Skeleton s a -> Skeleton t a
Files
- monad-skeleton.cabal +1/−1
- src/Control/Monad/Skeleton.hs +19/−1
monad-skeleton.cabal view
@@ -1,5 +1,5 @@ name: monad-skeleton -version: 0 +version: 0.1 synopsis: An undead monad description: A simple operational monad based on Reflection without Remorse homepage: https://github.com/fumieval/monad-skeleton
src/Control/Monad/Skeleton.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE RankNTypes, GADTs, PolyKinds #-}-module Control.Monad.Skeleton (Skeleton, MonadView(..), bone, unbone) where+module Control.Monad.Skeleton (MonadView(..), hoistMonadView, Skeleton, bone, unbone, hoistSkeleton) where import qualified Data.Sequence as Seq import Unsafe.Coerce import Control.Category@@ -19,15 +19,33 @@ bone :: t a -> Skeleton t a bone t = Skeleton (t :>>= return) id+{-# INLINABLE bone #-} +hoistSkeleton :: (forall x. s x -> t x) -> Skeleton s a -> Skeleton t a+hoistSkeleton f (Skeleton v c) = Skeleton (hoistMonadView f (hoistSkeleton f) v)+ (transCat (transKleisli (hoistSkeleton f)) c)+ data MonadView t m x where Return :: a -> MonadView t m a (:>>=) :: t a -> (a -> m b) -> MonadView t m b+infixl 1 :>>= +hoistMonadView :: (forall x. s x -> t x) -> (m a -> n a) -> MonadView s m a -> MonadView t n a+hoistMonadView _ _ (Return a) = Return a+hoistMonadView f g (t :>>= k) = f t :>>= g . k+ data Skeleton t a where Skeleton :: MonadView t (Skeleton t) x -> Cat (Kleisli (Skeleton t)) x a -> Skeleton t a newtype Cat k a b = Cat (Seq.Seq Any)++transKleisli :: (m b -> n b) -> Kleisli m a b -> Kleisli n a b+transKleisli f = unsafeCoerce (f.)+{-# INLINE transKleisli #-}++transCat :: (forall x y. j x y -> k x y) -> Cat j a b -> Cat k a b+transCat f (Cat s) = Cat (fmap (unsafeCoerce f) s)+{-# INLINE transCat #-} data View j k a b where Empty :: View j k a a