summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Parted/Types.hs
diff options
context:
space:
mode:
authorJoey Hess2018-04-23 13:20:13 -0400
committerJoey Hess2018-04-23 13:20:13 -0400
commit9228bda32f0a3f6d52e7cc5eb444376e7b024d8c (patch)
treee3ada017b0f625db8b39a2212ab82c8e32a62b7c /src/Propellor/Property/Parted/Types.hs
parent5ecbec11127449fefe4812fd6b374801ce8499c1 (diff)
semigroup monoid change fallout; drop ghc 7 support
Fix build with ghc 8.4, which broke due to the Semigroup Monoid change. See https://prime.haskell.org/wiki/Libraries/Proposals/SemigroupMonoid Dropped support for building propellor with ghc 7 (as in debian oldstable), to avoid needing to depend on the semigroups transitional package, but also because it's just too old to be worth supporting. If we indeed drop ghc 7 support entirely, some code to support "jessie" can be removed; concurrent-output can be de-embedded, and the Singletons code can be simplified. This commit was sponsored by Jack Hill on Patreon.
Diffstat (limited to 'src/Propellor/Property/Parted/Types.hs')
-rw-r--r--src/Propellor/Property/Parted/Types.hs23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/Propellor/Property/Parted/Types.hs b/src/Propellor/Property/Parted/Types.hs
index cfd8760d..5891cc16 100644
--- a/src/Propellor/Property/Parted/Types.hs
+++ b/src/Propellor/Property/Parted/Types.hs
@@ -4,6 +4,9 @@ import qualified Propellor.Property.Partition as Partition
import Utility.DataUnits
import Data.Char
+import qualified Data.Semigroup as Sem
+import Data.Monoid
+import Prelude
class PartedVal a where
pval :: a -> String
@@ -19,14 +22,17 @@ instance PartedVal TableType where
data PartTable = PartTable TableType Alignment [Partition]
deriving (Show)
-instance Monoid PartTable where
- -- | default TableType is MSDOS, with a `safeAlignment`.
- mempty = PartTable MSDOS safeAlignment []
+instance Sem.Semigroup PartTable where
-- | uses the TableType of the second parameter
-- and the larger alignment,
- mappend (PartTable _l1 a1 ps1) (PartTable l2 a2 ps2) =
+ PartTable _l1 a1 ps1 <> PartTable l2 a2 ps2 =
PartTable l2 (max a1 a2) (ps1 ++ ps2)
+instance Monoid PartTable where
+ -- | default TableType is MSDOS, with a `safeAlignment`.
+ mempty = PartTable MSDOS safeAlignment []
+ mappend = (<>)
+
-- | A partition on the disk.
data Partition = Partition
{ partType :: PartType
@@ -80,11 +86,14 @@ fromPartSize :: PartSize -> ByteSize
fromPartSize (MegaBytes b) = b * 1000000
fromPartSize (Bytes n) = n
+instance Sem.Semigroup PartSize where
+ MegaBytes a <> MegaBytes b = MegaBytes (a + b)
+ Bytes a <> b = Bytes (a + fromPartSize b)
+ a <> Bytes b = Bytes (b + fromPartSize a)
+
instance Monoid PartSize where
mempty = MegaBytes 0
- mappend (MegaBytes a) (MegaBytes b) = MegaBytes (a + b)
- mappend (Bytes a) b = Bytes (a + fromPartSize b)
- mappend a (Bytes b) = Bytes (b + fromPartSize a)
+ mappend = (<>)
reducePartSize :: PartSize -> PartSize -> PartSize
reducePartSize (MegaBytes a) (MegaBytes b) = MegaBytes (a - b)