packages feed

zippo (empty) → 0.1

raw patch · 5 files changed

+206/−0 lines, 5 filesdep +basedep +mtldep +yallsetup-changed

Dependencies added: base, mtl, yall

Files

+ Data/Lens/Zipper.hs view
@@ -0,0 +1,101 @@+{-# LANGUAGE TypeOperators+           , MultiParamTypeClasses, FlexibleContexts+           , TypeFamilies+           , FlexibleInstances #-}+module Data.Lens.Zipper (+{- |+   We provide a simple, heterogenous, fully type-checked, generic zipper+   implementation. This flavor of zipper doesn\'t use \"left\" and \"right\" for+   navigation, and instead relies on lenses to indicate a child type to \"move+   to\".+-}++  -- * Zipper type+    Zipper+  -- ** Zipper history +  , Top , (:>) , Hist++  -- * Zipper operations+  , zipper , close+  -- ** Motions+  , move , moveP , moveUp+  -- ** Focus+  , focus , setf , modf++ ) where++{- TODO+-      - excellent rewrite rules+-      - consider a newtype-wrapped submodule encapsulating monad return value+-      - more advanced motions a.la. pez?+-      - better demos+-}++import Data.Yall.Lens+import Control.Monad.Identity++-- | Our zipper type, parameterized by a 'focus' and \"history stack\",+-- supporting completely type-checked zipper operations.+data Zipper st b = Zipper { hist  :: st b , viewf :: b }+data (:>) st b c = Snoc (st b) (c -> b) +data Top a = Top++-- | A lens on the focus of the zipper.+focus :: Zipper st b :-> b+focus = lens viewf $ \z b-> z{ viewf = b }++-- | Set the zipper focus+--+-- > setf = set focus+setf :: Zipper st b -> b -> Zipper st b+setf = set focus++-- | Modify the zipper focus+--+-- > modf = modify focus+modf :: (b -> b) -> Zipper st b -> Zipper st b+modf = modify focus++-- | \"enter\" a data type. Move the 'focus' with 'move' and 'moveUp'. Exit+-- the zipper with 'close'.+--+-- > zipper = Zipper Top+zipper :: a -> Zipper Top a+zipper = Zipper Top+++class Hist st a c  where+     runHist :: st c -> (c -> a)+-- our only use of TypeFamilies. Thanks to Daniel Wagner for this trick:+instance a ~ b => Hist Top a b where+     runHist _ = id+instance (Hist st a b) => Hist ((:>) st b) a c where+     runHist (Snoc st' cb) = runHist st' . cb++-- | exit the zipper, rebuilding the structure @a@:+--+-- > close (Zipper st b) = runHist st b+close :: (Hist st a b)=> Zipper st b -> a+close (Zipper st b) = runHist st b++++-- | navigate to a child element indicated by the passed lens, returning the+-- new Zipper in the monad @m@. This will be 'Maybe' when the standard (':~>')+-- Lens is used. For pure lenses, use 'moveP'.+move :: (Monad m)=> LensM m b c -> Zipper st b -> m (Zipper (st :> b) c)+move l (Zipper st a) = +    liftM (uncurry $ Zipper . Snoc st . fmap runIdentity) (runLens l a)++-- | navigate to a child element indicated by the passed pure lens+--+-- > moveP l = runIdentity . move l+moveP :: (b :-> c) -> Zipper st b -> Zipper (st :> b) c+moveP l = runIdentity . move l+++-- | navigate up a level in a zipper not already at 'Top'+--+-- > moveUp (Zipper (Snoc st cont) c) = Zipper st $ cont c+moveUp :: Zipper (st :> b) c -> Zipper st b+moveUp (Zipper (Snoc st cont) c) = Zipper st $ cont c
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2012, Brandon Simmons++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Brandon Simmons nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,7 @@+A simple lens-based, lightweight, type-checked, heterogenous zipper library.++get with a ++    cabal install zippo++and check out the docs [here](http://hackage.haskell.org/package/zippo).
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ zippo.cabal view
@@ -0,0 +1,66 @@+-- zippo.cabal auto-generated by cabal init. For additional options,+-- see+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.+-- The name of the package.+Name:                zippo++-- The package version. See the Haskell package versioning policy+-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for+-- standards guiding when and how versions should be incremented.+Version:             0.1++-- A short (one-line) description of the package.+Synopsis:            A simple lens-based, generic, heterogenous, type-checked zipper library++-- A longer description of the package.+Description:         This light-weight library provides a basic, but fully-type-checked +                     zipper implementation, suitable for any algebraic data structure.+                     Our implementation has no notion of \"left\" and \"right\", and +                     instead uses lenses (from the "yall" package) to indicate directions+                     to \"navigate down to\".+                     .+                     For a similar approach with many more features, but less type-safety+                     see "pez".++-- URL for the project homepage or repository.+Homepage:            http://brandon.si/code/zippo/++-- The license under which the package is released.+License:             BSD3++-- The file containing the license text.+License-file:        LICENSE++-- The package author(s).+Author:              Brandon Simmons++-- An email address to which users can send suggestions, bug reports,+-- and patches.+Maintainer:          brandon.m.simmons@gmail.com++-- A copyright notice.+-- Copyright:           ++Category:            Data++Build-type:          Simple++-- Extra files to be distributed with the package, such as examples or+-- a README.+Extra-source-files:  README.md++Cabal-version:       >=1.6+++source-repository head   +    type:     git+    location: https://github.com/jberryman/zippo.git+    branch:   master++Library+  -- Modules exported by the library.+  Exposed-modules:     Data.Lens.Zipper+  +  Build-depends:       mtl >= 2+                     , yall +                     , base < 5 && >= 4