Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify dual #7

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2011-2013, dual-tree team:
Copyright (c) 2011-2015, dual-tree team:

Christopher Chalmers <[email protected]>
Jeffrey Rosenbluth <[email protected]>
Expand Down
66 changes: 31 additions & 35 deletions dual-tree.cabal
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
name: dual-tree
version: 0.2.0.6
version: 0.3.0.0
synopsis: Rose trees with cached and accumulating monoidal annotations
description: Rose (n-ary) trees with both upwards- (/i.e./
cached) and downwards-traveling (/i.e./
accumulating) monoidal annotations. This is used
as the core data structure underlying
the @diagrams@ framework
(<http://projects.haskell.org/diagrams>), but
potentially has other applications as well.
.
Abstractly, a DUALTree is a rose (n-ary) tree
with data (of type @l@) at leaves, data (of type
@a@) at internal nodes, and two types of monoidal
annotations, one (of type @u@) travelling \"up\"
the tree and one (of type @d@) traveling
\"down\".
.
See "Data.Tree.DUAL" for full documentation.
"Data.Tree.DUAL" provides a public API which
should suffice for most purposes.
"Data.Tree.DUAL.Internal" exports more of the
internal implementation---use it at your own
risk.
description:
Rose (n-ary) trees with both upwards- (/i.e./ cached) and
downwards-traveling (/i.e./ accumulating) monoidal annotations. This
is used as the core data structure underlying the @diagrams@ framework
(<http://projects.haskell.org/diagrams>), but potentially has other
applications as well.
.
Abstractly, a DUALTree is a rose (n-ary) tree with data (of type @l@)
at leaves, data (of type @a@) at internal nodes, and two types of
monoidal annotations, one (of type @u@) travelling \"up\" the tree and
one (of type @d@) traveling \"down\".
.
See "Data.Tree.DUAL" for full documentation. "Data.Tree.DUAL"
provides a public API which should suffice for most purposes.
"Data.Tree.DUAL.Internal" exports more of the internal
implementation---use it at your own risk.
license: BSD3
license-file: LICENSE
extra-source-files: CHANGES
Expand All @@ -38,17 +33,18 @@ source-repository head

library
default-language: Haskell2010
exposed-modules: Data.Tree.DUAL
Data.Tree.DUAL.Internal
build-depends: base >= 4.3 && < 4.9,
semigroups >= 0.8 && < 0.17,
newtype >= 0.2 && < 0.3,
monoid-extras >= 0.2 && < 0.5
exposed-modules:
Data.Tree.DUAL
Data.Tree.DUAL.Internal
build-depends:
base >= 4.3 && < 4.9,
semigroups >= 0.8 && < 0.17,
monoid-extras >= 0.2 && < 0.5,
deepseq,
containers
hs-source-dirs: src
other-extensions: GeneralizedNewtypeDeriving,
MultiParamTypeClasses,
FlexibleInstances,
DeriveFunctor,
TypeOperators,
FlexibleContexts,
DeriveDataTypeable
other-extensions:
BangPatterns CPP DeriveDataTypeable DeriveFunctor DeriveTraversable
FlexibleContexts FlexibleInstances LambdaCase MultiParamTypeClasses
TypeOperators

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the other-extensions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't actually remember. I'll add it back.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Of course the specific list of extensions used has probably changed.

69 changes: 32 additions & 37 deletions src/Data/Tree/DUAL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-----------------------------------------------------------------------------
-- |
-- Module : Data.Tree.DUAL
-- Copyright : (c) 2011-2012 Brent Yorgey
-- Copyright : (c) 2011-2015 dual-tree team (see LICENSE)
-- License : BSD-style (see LICENSE)
-- Maintainer : [email protected]
--
Expand All @@ -17,24 +17,13 @@
-- of monoidal annotations, one (of type @u@) travelling \"up\" the
-- tree and one (of type @d@) traveling \"down\".
--
-- Specifically, there are five types of nodes:
-- Specifically, there are three types of nodes:
--
-- * Leaf nodes which contain a data value of type @l@ and an
-- annotation of type @u@. The annotation represents information
-- about a tree that should be accumulated (/e.g./ number of
-- leaves, some sort of \"weight\", /etc./). If you are familiar
-- with finger trees
-- (<http://www.soi.city.ac.uk/~ross/papers/FingerTree.html>,
-- <http://hackage.haskell.org/package/fingertree>), it is the
-- same idea.
--
-- * There is also a special type of leaf node which contains only a
-- @u@ value, and no data. This allows cached @u@ values to be
-- \"modified\" by inserting extra annotations.
-- * Leaf nodes which contain a data value of type @l@.
--
-- * Branch nodes, containing a list of subtrees.
--
-- * Internal nodes with a value of type @d@. @d@ may have an
-- * Internal nodes with a value of type @d@. @d@ may have an
-- /action/ on @u@ (see the 'Action' type class, defined in
-- "Data.Monoid.Action" from the @monoid-extras@ package).
-- Semantically speaking, applying a @d@ annotation to a tree
Expand All @@ -44,45 +33,51 @@
-- constant time.
--
-- * Internal nodes with data values of type @a@, possibly of a
-- different type than those in the leaves. These are just \"along
-- for the ride\" and are unaffected by @u@ and @d@ annotations.
-- different type than those in the leaves. These annotations are
-- acted on by any @d@ annotations above it.
--
-- The @u@ annotation represents information about a tree that should
-- be accumulated (/e.g./ number of leaves, some sort of \"weight\",
-- /etc./). If you are familiar with finger trees
-- (<http://www.soi.city.ac.uk/~ross/papers/FingerTree.html>,
-- <http://hackage.haskell.org/package/fingertree>), it is the same
-- idea.
--
-- There are two critical points to note about @u@ and @d@ annotations:
--
-- * The combined @u@ annotation for an entire tree is always cached
-- at the root and available in constant (amortized) time.
-- at the root and available in constant time.
--
-- * The 'mconcat' of all the @d@ annotations along the path from
-- the root to each leaf is available along with the leaf during a
-- fold operation.
--
-- A fold over a @DUALTree@ is given access to the internal and leaf
-- data, and the accumulated @d@ values at each leaf. It is also
-- allowed to replace \"@u@-only\" leaves with a constant value. In
-- particular, however, it is /not/ given access to any of the @u@
-- annotations, the idea being that those are used only for
-- /constructing/ trees. It is also not given access to @d@ values as
-- they occur in the tree, only as they accumulate at leaves. If you
-- do need access to @u@ or @d@ values, you can duplicate the values
-- you need in the internal data nodes.
-- data, and the accumulated @d@ values at each leaf. In particular,
-- however, it is /not/ given access to any of the @u@ annotations, the
-- idea being that those are used only for /constructing/ trees. It is
-- also not given access to @d@ values as they occur in the tree, only
-- as they accumulate at leaves. If you do need access to @u@ or @d@
-- values, you can duplicate the values you need in the internal data
-- nodes.
--
-----------------------------------------------------------------------------

module Data.Tree.DUAL
(
-- * DUAL-trees
DUALTree
(
-- * DUAL-trees
DUALTree

-- * Constructing DUAL-trees
, empty, leaf, leafU, annot, applyD
-- * Constructing DUAL-trees
, leaf, leafU, annot, down

-- * Modifying DUAL-trees
, applyUpre, applyUpost
, mapU
-- * Modifying DUAL-trees
, _u, mapU, preapplyU, postapplyU

-- * Accessors and eliminators
, getU, foldDUAL, flatten
-- * Accessors and eliminators
, getU, foldDUAL, foldDUAL', flatten

) where
) where

import Data.Tree.DUAL.Internal

Loading