-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
darcs-hash:20061211032153-9c5c1-ffa6da3f510681db5293d3cac0a0a4b8a4a3dcbf
- Loading branch information
0 parents
commit 7464bf4
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
----------------------------------------------------------------------------- | ||
-- | | ||
-- Module : Data.DList | ||
-- Copyright : (c) Don Stewart 2006 | ||
-- License : BSD-style (see the file LICENSE) | ||
-- | ||
-- Maintainer : [email protected] | ||
-- Stability : experimental | ||
-- Portability : portable (Haskell 98) | ||
-- | ||
-- Difference lists: a data structure for O(1) append on lists. | ||
-- | ||
----------------------------------------------------------------------------- | ||
|
||
module Data.DList ( | ||
|
||
DList, -- abstract | ||
|
||
-- * Construction | ||
fromList, -- :: [a] -> DList a | ||
toList, -- :: DList a -> [a] | ||
|
||
-- * Basic functions | ||
empty, -- :: DList a | ||
singleton, -- :: a -> DList a | ||
snoc, -- :: DList a -> a -> DList a | ||
append, -- :: DList a -> DList a -> DList a | ||
|
||
|
||
) where | ||
|
||
-- | A difference list is a function that given a list, returns the | ||
-- original contents of the difference list prepended at the given list | ||
-- | ||
-- This structure supports /O(1)/ append/snoc operations on lists | ||
-- | ||
type DList a = [a] -> [a] | ||
|
||
-- | Converting a normal list to a dlist | ||
fromList :: [a] -> DList a | ||
fromList = (++) | ||
|
||
-- | Converting a dlist back to a normal list | ||
toList :: DList a -> [a] | ||
toList = ($[]) | ||
|
||
-- | Create a difference list containing no elements | ||
empty :: DList a | ||
empty = id | ||
|
||
-- | Create difference list with given single element | ||
singleton :: a -> DList a | ||
singleton = (:) | ||
|
||
-- | /O(1)/, Append a single element at a difference list | ||
snoc :: DList a -> a -> DList a | ||
snoc = (. (:)) . (.) | ||
|
||
-- | Appending difference lists | ||
append :: DList a -> DList a -> DList a | ||
append = (.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env runhaskell | ||
> import Distribution.Simple | ||
> main = defaultMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Name: dlist | ||
Version: 0.1 | ||
Description: Differences lists: lists supporting efficient append | ||
License: BSD3 | ||
License-file: LICENSE | ||
Author: Don Stewart | ||
Maintainer: <[email protected]> | ||
Build-Depends: base | ||
ghc-options: -O | ||
Exposed-modules: Data.DList |