LTree (empty) → 0.0
raw patch · 4 files changed
+99/−0 lines, 4 filesdep +basedep +transformerssetup-changed
Dependencies added: base, transformers
Files
- Data/Trees/LTree.hs +56/−0
- LICENSE +15/−0
- LTree.cabal +26/−0
- Setup.hs +2/−0
+ Data/Trees/LTree.hs view
@@ -0,0 +1,56 @@+-- |+-- Module : Data.Trees.LTree+-- Copyright : Rahul Gopinath+-- License : PublicDomain+-- +-- Maintainer : Rahul Gopinath (gopinath@eecs.oregonstate.edu)+-- Stability : experimental+-- Portability : portable+-- +-- This Haskell library provides an implementation of a tree data+-- type with content in the leaves.+-- +module Data.Trees.LTree(Tree(..)) where++import Control.Monad+import Data.Monoid+import Data.Foldable +import Data.Traversable +import Data.Typeable++import qualified Data.Traversable as Tr+import qualified Data.Foldable as Fl+import qualified Data.Monoid as Monoid (mappend, mempty, mconcat, Monoid)++import Control.Applicative++-- |+-- | The @LTree c@ is a tree structure with content in the leaves.+data Tree c = Leaf { content :: c }+ | Node { trees :: [Tree c]}+ deriving (Show,Eq)++instance Functor Tree where + fmap f (Leaf c) = Leaf $ f c+ fmap f (Node l) = Node $ map (fmap f) l++instance Applicative Tree where+ pure c = Leaf c + Node l <*> t = Node (map (<*> t) l)+ Leaf c <*> Node l = Node (map (c <$>) l)+ Leaf c <*> Leaf c' = Leaf (c c')++instance Monad Tree where+ return x = Leaf x+ Node l >>= f = Node (map (>>= f) l)+ Leaf c >>= f = f c++instance Foldable Tree where+ foldMap f (Node l) = foldMap (foldMap f) l+ foldMap f (Leaf c) = f c++instance Traversable Tree where+ traverse f (Node l) = Node <$> traverse (traverse f) l+ traverse f (Leaf c) = Leaf <$> f c++
+ LICENSE view
@@ -0,0 +1,15 @@+ALL PUBLIC DOMAIN MATERIAL IS OFFERED AS-IS. NO REPRESENTATIONS OR+WARRANTIES OF ANY KIND ARE MADE CONCERNING THE MATERIALS, EXPRESS,+IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION,+WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR+PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS,+ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT+DISCOVERABLE.++IN NO EVENT WILL THE AUTHOR(S), PUBLISHER(S), OR PRESENTER(S) OF ANY+PUBLIC DOMAIN MATERIAL BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY+SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES+ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF THE+AUTHOR(S), PUBLISHER(S), OR PRESENTER(S) HAVE BEEN ADVISED OF THE+POSSIBILITY OF SUCH DAMAGES.+
+ LTree.cabal view
@@ -0,0 +1,26 @@+Name: LTree+Version: 0.0+Cabal-Version: >=1.6+Synopsis: Tree with only leaves carrying the data.+Description:++ This Haskell library provides an implementation of+ a tree data type with content only in the leaves, and its+ corresponding transformer.++Category: Data+License: PublicDomain+License-File: LICENSE+Author: Rahul Gopinath+Maintainer: gopinath@eecs.oregonstate.edu+Bug-Reports: mailto:gopinath@eecs.oregonstate.edu+Build-Type: Simple+Stability: experimental++Library+ Build-Depends: base >= 2 && < 5, transformers+ Exposed-Modules: Data.Trees.LTree++Source-Repository head+ type: darcs+ location:
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain