Skip to content

Commit

Permalink
Implemented automatic derivation of monadic datatypes and correspondi…
Browse files Browse the repository at this point in the history
…ng instances.

See documentation of module Data.Monadic.Derive.
  • Loading branch information
sebfisch committed Mar 15, 2010
1 parent 4195b53 commit 890e424
Show file tree
Hide file tree
Showing 5 changed files with 492 additions and 7 deletions.
16 changes: 13 additions & 3 deletions Control/Monad/Sharing/Classes.hs
Expand Up @@ -19,7 +19,9 @@
-- sharing.
module Control.Monad.Sharing.Classes (

Sharing(..), Shareable(..), Convertible(..), convert
Sharing(..), Shareable(..), Convertible(..), convert,

MInt, MChar, MBool

) where

Expand All @@ -44,8 +46,12 @@ class Sharing m
-- could be applied.
class Shareable m a
where
shareArgs :: Monad n
=> (forall b . Shareable m b => m b -> n (m b)) -> a -> n a
shareArgs :: Monad n =>
(forall b . Shareable m b => m b -> n (m b)) -> a -> n a

type MInt m = Int
type MChar m = Char
type MBool m = Bool

instance Monad m => Shareable m Bool
where
Expand All @@ -71,6 +77,10 @@ instance Monad m => Shareable m [Char]
where
shareArgs _ = return

instance Monad m => Shareable m (a -> b)
where
shareArgs _ = return

-- | An instance for lists with monadic elements.
instance (Monad m, Shareable m a) => Shareable m [m a]
where
Expand Down
2 changes: 1 addition & 1 deletion Control/Monad/Sharing/Implementation/CPS.hs
Expand Up @@ -104,7 +104,7 @@ instance Monad m => MonadState Store (Lazy m)
-- 'Lazy' is a monad transformer.
instance MonadTrans Lazy
where
lift a = Lazy (\c s -> a >>= \x -> c x s)
lift a = Lazy (\c s -> a >>= flip c s)

-- If the underlying monad supports IO we can lift this functionality.
instance MonadIO m => MonadIO (Lazy m)
Expand Down

0 comments on commit 890e424

Please sign in to comment.