Simplify instance declarations

Many instance declarations can now be derived either by DerivingVia or
GeneralizedNewtypeDeriving.
This commit is contained in:
Tony Zorman
2022-11-19 09:10:57 +01:00
parent 5d0013ef53
commit b96bb908db
4 changed files with 20 additions and 47 deletions

View File

@@ -1,4 +1,8 @@
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, PatternGuards #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PatternGuards #-}
-----------------------------------------------------------------------------
-- |
-- Module : XMonad.Layout.Mosaic
@@ -179,16 +183,7 @@ normalize :: Fractional a => [a] -> [a]
normalize x = let s = sum x in map (/s) x
data Tree a = Branch (Tree a) (Tree a) | Leaf a | Empty
instance Foldable Tree where
foldMap _f Empty = mempty
foldMap f (Leaf x) = f x
foldMap f (Branch l r) = foldMap f l `mappend` foldMap f r
instance Functor Tree where
fmap f (Leaf x) = Leaf $ f x
fmap f (Branch l r) = Branch (fmap f l) (fmap f r)
fmap _ Empty = Empty
deriving (Functor, Show, Foldable)
instance Semigroup (Tree a) where
Empty <> x = x