X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FSequence.hs;h=7827ba671a28ab883c8535df0c1ecad9426b48be;hb=0df0a6b4d9d9bc5faa3ff8a9a886e20b5fd4e30c;hp=ccc7e6c10d5280f2ac4e251e19eed93e8d70b4c1;hpb=78967933576017b0e6ba57863c8f1d877939d539;p=haskell-directory.git diff --git a/Data/Sequence.hs b/Data/Sequence.hs index ccc7e6c..7827ba6 100644 --- a/Data/Sequence.hs +++ b/Data/Sequence.hs @@ -67,7 +67,7 @@ import Prelude hiding ( null, length, take, drop, splitAt, foldl, foldl1, foldr, foldr1, reverse) import qualified Data.List (foldl') -import Control.Applicative (Applicative(..)) +import Control.Applicative (Applicative(..), (<$>)) import Control.Monad (MonadPlus(..)) import Data.Monoid (Monoid(..)) import Data.Foldable @@ -100,7 +100,7 @@ class Sized a where newtype Seq a = Seq (FingerTree (Elem a)) instance Functor Seq where - fmap = fmapDefault + fmap f (Seq xs) = Seq (fmap (fmap f) xs) instance Foldable Seq where foldr f z (Seq xs) = foldr (flip (foldr f)) z xs @@ -223,6 +223,12 @@ instance Foldable FingerTree where foldl1 f (Deep _ pr m sf) = foldl f (foldl (foldl f) (foldl1 f pr) m) sf +instance Functor FingerTree where + fmap _ Empty = Empty + fmap f (Single x) = Single (f x) + fmap f (Deep v pr m sf) = + Deep v (fmap f pr) (fmap (fmap f) m) (fmap f sf) + instance Traversable FingerTree where traverse _ Empty = pure Empty traverse f (Single x) = Single <$> f x @@ -268,6 +274,9 @@ instance Foldable Digit where foldl1 f (Three a b c) = (a `f` b) `f` c foldl1 f (Four a b c d) = ((a `f` b) `f` c) `f` d +instance Functor Digit where + fmap = fmapDefault + instance Traversable Digit where traverse f (One a) = One <$> f a traverse f (Two a b) = Two <$> f a <*> f b @@ -303,6 +312,9 @@ instance Foldable Node where foldl f z (Node2 _ a b) = (z `f` a) `f` b foldl f z (Node3 _ a b c) = ((z `f` a) `f` b) `f` c +instance Functor Node where + fmap = fmapDefault + instance Traversable Node where traverse f (Node2 v a b) = Node2 v <$> f a <*> f b traverse f (Node3 v a b c) = Node3 v <$> f a <*> f b <*> f c