Skip to content

Instantly share code, notes, and snippets.

@yihuang
Created March 28, 2012 04:24
Show Gist options
  • Save yihuang/2223610 to your computer and use it in GitHub Desktop.
Save yihuang/2223610 to your computer and use it in GitHub Desktop.
dlist
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