Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

3.0 conversion

  • Loading branch information...
commit 7c89e2b4ee17afab2f43026d2079a2e59b7ed9d7 1 parent ead8c83
Edward Kmett authored
11 comonad-extras.cabal
... ... @@ -1,6 +1,6 @@
1 1 name: comonad-extras
2 2 category: Control, Comonads
3   -version: 2.1.2
  3 +version: 3.0
4 4 license: BSD3
5 5 cabal-version: >= 1.6
6 6 license-file: LICENSE
@@ -20,6 +20,7 @@ source-repository head
20 20 location: git://github.com/ekmett/comonad-extras.git
21 21
22 22 library
  23 + hs-source-dirs: src
23 24 extensions: CPP
24 25
25 26 other-extensions:
@@ -34,11 +35,11 @@ library
34 35 array >= 0.3 && < 0.5,
35 36 base >= 4 && < 5,
36 37 containers >= 0.4 && < 0.6,
37   - comonad >= 1.1.1.5 && < 1.2,
38   - comonad-transformers >= 2.1.2 && < 2.2,
39   - comonads-fd >= 2.1.2 && < 2.2,
  38 + comonad >= 3.0 && < 3.1,
  39 + comonad-transformers >= 3.0 && < 3.1,
  40 + comonads-fd >= 3.0 && < 3.1,
40 41 distributive >= 0.2.2 && < 0.3,
41   - semigroupoids >= 1.3.1.2 && < 1.4,
  42 + semigroupoids >= 3.0 && < 3.1,
42 43 transformers >= 0.2 && < 0.4
43 44
44 45 exposed-modules:
14 Control/Comonad/Store/Pointer.hs → src/Control/Comonad/Store/Pointer.hs
... ... @@ -1,8 +1,12 @@
1   -{-# LANGUAGE CPP, FlexibleInstances, MultiParamTypeClasses, FunctionalDependencies, UndecidableInstances #-}
  1 +{-# LANGUAGE CPP #-}
  2 +{-# LANGUAGE FlexibleInstances #-}
  3 +{-# LANGUAGE MultiParamTypeClasses #-}
  4 +{-# LANGUAGE FunctionalDependencies #-}
  5 +{-# LANGUAGE UndecidableInstances #-}
2 6 -----------------------------------------------------------------------------
3 7 -- |
4 8 -- Module : Control.Comonad.Store.Pointer
5   --- Copyright : (C) 2008-2011 Edward Kmett
  9 +-- Copyright : (C) 2008-2012 Edward Kmett
6 10 -- License : BSD-style (see the file LICENSE)
7 11 --
8 12 -- Maintainer : Edward Kmett <ekmett@gmail.com>
@@ -45,6 +49,7 @@ import Control.Comonad.Store.Class
45 49 import Control.Comonad.Traced.Class
46 50 import Control.Comonad.Env.Class
47 51 import Data.Functor.Identity
  52 +import Data.Functor.Extend
48 53 import Data.Array
49 54
50 55 #ifdef __GLASGOW_HASKELL__
@@ -86,11 +91,12 @@ instance (Functor w, Ix i) => Functor (PointerT i w) where
86 91 fmap f (PointerT g i) = PointerT (fmap f <$> g) i
87 92
88 93 instance (Comonad w, Ix i) => Extend (PointerT i w) where
  94 + duplicated = duplicate
  95 +
  96 +instance (Comonad w, Ix i) => Comonad (PointerT i w) where
89 97 duplicate (PointerT g i) = PointerT (extend p g) i where
90 98 p wa = listArray b $ PointerT wa <$> range b where
91 99 b = bounds (extract wa)
92   -
93   -instance (Comonad w, Ix i) => Comonad (PointerT i w) where
94 100 extract (PointerT g i) = extract g ! i
95 101
96 102 instance Ix i => ComonadTrans (PointerT i) where
0  Control/Comonad/Store/Zapper.hs → src/Control/Comonad/Store/Zapper.hs
File renamed without changes
37 Control/Comonad/Store/Zipper.hs → src/Control/Comonad/Store/Zipper.hs
... ... @@ -1,13 +1,23 @@
1   -{-# LANGUAGE Rank2Types, MultiParamTypeClasses #-}
  1 +{-# LANGUAGE Rank2Types #-}
  2 +{-# LANGUAGE MultiParamTypeClasses #-}
2 3 {-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
3   -
4   -
5   -module Control.Comonad.Store.Zipper
  4 +-----------------------------------------------------------------------------
  5 +-- |
  6 +-- Module : Control.Comonad.Store.Zipper
  7 +-- Copyright : (C) 2008-2012 Edward Kmett,
  8 +-- License : BSD-style (see the file LICENSE)
  9 +--
  10 +-- Maintainer : Edward Kmett <ekmett@gmail.com>
  11 +-- Stability : experimental
  12 +-- Portability : portable
  13 +--
  14 +----------------------------------------------------------------------------
  15 +module Control.Comonad.Store.Zipper
6 16 ( Zipper, zipper, zipper1, unzipper, size) where
7 17
8 18 import Control.Applicative
9   -import Control.Comonad (Extend(..), Comonad(..))
10   -
  19 +import Control.Comonad (Comonad(..))
  20 +import Data.Functor.Extend
11 21 import Data.Foldable
12 22 import Data.Traversable
13 23 import Data.Semigroup.Traversable
@@ -16,18 +26,18 @@ import qualified Data.Sequence as Seq
16 26 import Control.Comonad.Store (ComonadStore(..))
17 27 import Data.Maybe (fromJust)
18 28
19   -data Zipper t a = Zipper (forall b. Seq b -> t b) {-# UNPACK #-} !Int !(Seq a)
  29 +data Zipper t a = Zipper (forall b. Seq b -> t b) {-# UNPACK #-} !Int !(Seq a)
20 30
21 31 zipper :: Traversable t => t a -> Maybe (Zipper t a)
22 32 zipper t = case toList t of
23 33 [] -> Nothing
24   - xs -> Just (Zipper (refill t) 0 (Seq.fromList xs))
  34 + xs -> Just (Zipper (refill t) 0 (Seq.fromList xs))
25 35 where refill bs as = snd (mapAccumL (\(a:as') _ -> (as', a)) (toList as) bs)
26 36
27 37 zipper1 :: Traversable1 t => t a -> Zipper t a
28 38 zipper1 = fromJust . zipper
29   -
30   -unzipper :: Zipper t a -> t a
  39 +
  40 +unzipper :: Zipper t a -> t a
31 41 unzipper (Zipper t _ s) = t s
32 42
33 43 size :: Zipper t a -> Int
@@ -44,11 +54,12 @@ instance Functor (Zipper t) where
44 54 instance Foldable (Zipper t) where
45 55 foldMap f (Zipper _ _ s) = foldMap f s
46 56
47   -instance Traversable (Zipper t) where
  57 +instance Traversable (Zipper t) where
48 58 traverse f (Zipper t i s) = Zipper t i <$> traverse f s
49 59
50 60 instance Extend (Zipper t) where
51   - extend f (Zipper t i s) = Zipper t i (Seq.mapWithIndex (\j _ -> f (Zipper t j s)) s)
  61 + extended = extend
52 62
53 63 instance Comonad (Zipper t) where
54   - extract (Zipper _ i s) = Seq.index s i
  64 + extend f (Zipper t i s) = Zipper t i (Seq.mapWithIndex (\j _ -> f (Zipper t j s)) s)
  65 + 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.