Created
March 28, 2012 04:24
-
-
Save yihuang/2223610 to your computer and use it in GitHub Desktop.
dlist
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
module DList where | |
import Prelude hiding (reverse) | |
import Prelude as P | |
{- | |
- provide whatever list operation in O(1) time complexity ... | |
- only toList do all the hard works. | |
-} | |
type DList a = [a] -> [a] | |
addFirst :: a -> DList a -> DList a | |
addFirst a l = (a:) . l | |
addLast :: a -> DList a -> DList a | |
addLast a l = (++[a]) . l | |
remove :: Ord a => a -> DList a -> DList a | |
remove a l = filter (/=a) . l | |
reverse :: a -> DList a -> DList a | |
reverse a l = P.reverse . l | |
fromList :: [a] -> DList a | |
fromList = (++) | |
toList :: DList a -> [a] | |
toList dl = dl [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment