Skip to content
Browse files

3.0 conversion

  • Loading branch information...
1 parent ead8c83 commit 7c89e2b4ee17afab2f43026d2079a2e59b7ed9d7 @ekmett committed Jul 5, 2012
View
11 comonad-extras.cabal
@@ -1,6 +1,6 @@
name: comonad-extras
category: Control, Comonads
-version: 2.1.2
+version: 3.0
license: BSD3
cabal-version: >= 1.6
license-file: LICENSE
@@ -20,6 +20,7 @@ source-repository head
location: git://github.com/ekmett/comonad-extras.git
library
+ hs-source-dirs: src
extensions: CPP
other-extensions:
@@ -34,11 +35,11 @@ library
array >= 0.3 && < 0.5,
base >= 4 && < 5,
containers >= 0.4 && < 0.6,
- comonad >= 1.1.1.5 && < 1.2,
- comonad-transformers >= 2.1.2 && < 2.2,
- comonads-fd >= 2.1.2 && < 2.2,
+ comonad >= 3.0 && < 3.1,
+ comonad-transformers >= 3.0 && < 3.1,
+ comonads-fd >= 3.0 && < 3.1,
distributive >= 0.2.2 && < 0.3,
- semigroupoids >= 1.3.1.2 && < 1.4,
+ semigroupoids >= 3.0 && < 3.1,
transformers >= 0.2 && < 0.4
exposed-modules:
View
14 Control/Comonad/Store/Pointer.hs → src/Control/Comonad/Store/Pointer.hs
@@ -1,8 +1,12 @@
-{-# LANGUAGE CPP, FlexibleInstances, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-}
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE FunctionalDependencies #-}
+{-# LANGUAGE UndecidableInstances #-}
-----------------------------------------------------------------------------
-- |
-- Module : Control.Comonad.Store.Pointer
--- Copyright : (C) 2008-2011 Edward Kmett
+-- Copyright : (C) 2008-2012 Edward Kmett
-- License : BSD-style (see the file LICENSE)
--
-- Maintainer : Edward Kmett <ekmett@gmail.com>
@@ -45,6 +49,7 @@ import Control.Comonad.Store.Class
import Control.Comonad.Traced.Class
import Control.Comonad.Env.Class
import Data.Functor.Identity
+import Data.Functor.Extend
import Data.Array
#ifdef __GLASGOW_HASKELL__
@@ -86,11 +91,12 @@ instance (Functor w, Ix i) => Functor (PointerT i w) where
fmap f (PointerT g i) = PointerT (fmap f <$> g) i
instance (Comonad w, Ix i) => Extend (PointerT i w) where
+ duplicated = duplicate
+
+instance (Comonad w, Ix i) => Comonad (PointerT i w) where
duplicate (PointerT g i) = PointerT (extend p g) i where
p wa = listArray b $ PointerT wa <$> range b where
b = bounds (extract wa)
-
-instance (Comonad w, Ix i) => Comonad (PointerT i w) where
extract (PointerT g i) = extract g ! i
instance Ix i => ComonadTrans (PointerT i) where
View
0 Control/Comonad/Store/Zapper.hs → src/Control/Comonad/Store/Zapper.hs
File renamed without changes.
View
37 Control/Comonad/Store/Zipper.hs → src/Control/Comonad/Store/Zipper.hs
@@ -1,13 +1,23 @@
-{-# LANGUAGE Rank2Types, MultiParamTypeClasses #-}
+{-# LANGUAGE Rank2Types #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
-
-
-module Control.Comonad.Store.Zipper
+-----------------------------------------------------------------------------
+-- |
+-- Module : Control.Comonad.Store.Zipper
+-- Copyright : (C) 2008-2012 Edward Kmett,
+-- License : BSD-style (see the file LICENSE)
+--
+-- Maintainer : Edward Kmett <ekmett@gmail.com>
+-- Stability : experimental
+-- Portability : portable
+--
+----------------------------------------------------------------------------
+module Control.Comonad.Store.Zipper
( Zipper, zipper, zipper1, unzipper, size) where
import Control.Applicative
-import Control.Comonad (Extend(..), Comonad(..))
-
+import Control.Comonad (Comonad(..))
+import Data.Functor.Extend
import Data.Foldable
import Data.Traversable
import Data.Semigroup.Traversable
@@ -16,18 +26,18 @@ import qualified Data.Sequence as Seq
import Control.Comonad.Store (ComonadStore(..))
import Data.Maybe (fromJust)
-data Zipper t a = Zipper (forall b. Seq b -> t b) {-# UNPACK #-} !Int !(Seq a)
+data Zipper t a = Zipper (forall b. Seq b -> t b) {-# UNPACK #-} !Int !(Seq a)
zipper :: Traversable t => t a -> Maybe (Zipper t a)
zipper t = case toList t of
[] -> Nothing
- xs -> Just (Zipper (refill t) 0 (Seq.fromList xs))
+ xs -> Just (Zipper (refill t) 0 (Seq.fromList xs))
where refill bs as = snd (mapAccumL (\(a:as') _ -> (as', a)) (toList as) bs)
zipper1 :: Traversable1 t => t a -> Zipper t a
zipper1 = fromJust . zipper
-
-unzipper :: Zipper t a -> t a
+
+unzipper :: Zipper t a -> t a
unzipper (Zipper t _ s) = t s
size :: Zipper t a -> Int
@@ -44,11 +54,12 @@ instance Functor (Zipper t) where
instance Foldable (Zipper t) where
foldMap f (Zipper _ _ s) = foldMap f s
-instance Traversable (Zipper t) where
+instance Traversable (Zipper t) where
traverse f (Zipper t i s) = Zipper t i <$> traverse f s
instance Extend (Zipper t) where
- extend f (Zipper t i s) = Zipper t i (Seq.mapWithIndex (\j _ -> f (Zipper t j s)) s)
+ extended = extend
instance Comonad (Zipper t) where
- extract (Zipper _ i s) = Seq.index s i
+ extend f (Zipper t i s) = Zipper t i (Seq.mapWithIndex (\j _ -> f (Zipper t j s)) s)
+ extract (Zipper _ i s) = Seq.index s i

0 comments on commit 7c89e2b

Please sign in to comment.
Something went wrong with that request. Please try again.