{-# LANGUAGE GADTs,TypeSynonymInstances,MultiParamTypeClasses #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Comonad.Doubled -- Copyright : (C) 2010 Thomas Bereknyei -- License : BSD-style (see the file LICENSE) -- -- Maintainer : Thomas Bereknyei -- Stability : experimental -- Portability : portable -- ---------------------------------------------------------------------------- module Comonad2 ( DCopointed(..) , DComonad(..) , DFunctor(..) ,dextendX ,(=>>) ) where import Data.List (foldl') class (DCopointed g f) => DComonad g f where dextend :: (g a b -> f c d) -> g a b -> g c d class (DFunctor g f) => DCopointed g f where dextract :: g a b -> f a b class DFunctor g f where dmap :: (f a b -> f c d) -> g a b -> g c d dextendX :: DComonad g f => (g a b -> f a b) -> Int -> g a b -> g a b dextendX f t = foldl' (.) id (take t $ repeat $ dextend f) --dextendX function times net = (iterate (dextend function) net)!!times (=>>) :: DComonad g f => g a b-> (g a b-> f a b) -> g a b (=>>) = flip dextend {-# RULES "dextend pextract" dextend dextract = id "dextract . dextend g" forall g. dextract . dextend g = g "dextend f . dextend g" forall f g. dextend f.dextend g=dextend (f.dextend g) #-}