Give proper foldl' and foldr methods for LTrees
This commit is contained in:
+10
-2
@@ -4,8 +4,8 @@ module Picture.Data
|
||||
where
|
||||
import Geometry.Data
|
||||
|
||||
--import Data.Foldable
|
||||
|
||||
import Data.Foldable
|
||||
--import qualified Data.List as L
|
||||
--import Data.Monoid
|
||||
--import Data.Traversable
|
||||
--import qualified Data.Foldable as F
|
||||
@@ -54,6 +54,14 @@ instance Foldable LTree where
|
||||
foldMap g (LBranches ts) = mconcat $ map (foldMap g) ts
|
||||
foldMap g (LLeaf a) = g a
|
||||
{-# INLINE foldMap #-}
|
||||
foldr _ x (LBranches []) = x
|
||||
foldr g x (LBranches (t:ts)) = foldr g (foldr g x (LBranches ts)) t
|
||||
foldr g x (LLeaf y) = g y x
|
||||
{-# INLINE foldr #-}
|
||||
foldl' _ x (LBranches []) = x
|
||||
foldl' g x (LBranches (t:ts)) = foldl' g x t `seq` foldl' g (foldl' g x t) (LBranches ts)
|
||||
foldl' g x (LLeaf y) = g x y
|
||||
{-# INLINE foldl' #-}
|
||||
instance Functor LTree where
|
||||
fmap f (LBranches ts) = LBranches $ fmap (fmap f) ts
|
||||
fmap f (LLeaf x) = LLeaf (f x)
|
||||
|
||||
Reference in New Issue
Block a user