{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
------------------------------------------------------------------------------- |-- Module : Control.Comonad.Cofree.Class-- Copyright : (C) 2008-2011 Edward Kmett-- License : BSD-style (see the file LICENSE)---- Maintainer : Edward Kmett <ekmett@gmail.com>-- Stability : experimental-- Portability : fundeps, MPTCs----------------------------------------------------------------------------
module Control.Comonad.Cofree.Class
( ComonadCofree(..)
) where
import Control.Applicative
import Control.Comonad
import Control.Comonad.Trans.Env
import Control.Comonad.Trans.Store
import Control.Comonad.Trans.Traced
import Control.Comonad.Trans.Identity
import Data.List.NonEmpty
import Data.Semigroup-- | Allows you to peel a layer off a cofree comonad.
class (Functor f, Comonad w) =>ComonadCofreefw | w -> f where
-- | Remove a layer.unwrap :: wa -> f (wa)
instance ComonadCofreeMaybeNonEmpty where
unwrap (_ :| []) = Nothingunwrap (_ :| (a:as)) = Just (a:|as)
instance ComonadCofree (Constb) ((,)b) where
unwrap = Const.fst
instance ComonadCofree f w =>ComonadCofreef (IdentityTw) where
unwrap = fmapIdentityT.unwrap.runIdentityT
instance ComonadCofree f w =>ComonadCofreef (EnvTew) where
unwrap (EnvTewa) = EnvTe<$>unwrapwa
instance ComonadCofree f w =>ComonadCofreef (StoreTsw) where
unwrap (StoreTwsas) = flipStoreTs<$>unwrapwsa
instance (ComonadCofree f w, Semigroup m, Monoid m) =>ComonadCofreef (TracedTmw) where
unwrap (TracedTwma) = TracedT<$>unwrapwma