diff options
author | Kosyrev Serge <serge.kosyrev@iohk.io> | 2018-01-16 03:12:01 +0300 |
---|---|---|
committer | Kosyrev Serge <serge.kosyrev@iohk.io> | 2018-01-16 03:12:01 +0300 |
commit | f844c6f6179eb0a9a0921e26d59cd7fca40520d7 (patch) | |
tree | 1e99cf9caf7b0d8b8ff58ea63a80829611f6f8c2 /prototypes | |
parent | cbac76692978c316223eda2407deda4978a09241 (diff) |
Semigroup-Monoid Proposal fixes: GHC 8.4 compat
Diffstat (limited to 'prototypes')
-rw-r--r-- | prototypes/FreeVars.hs | 24 | ||||
-rw-r--r-- | prototypes/LamMachineV2.hs | 6 | ||||
-rw-r--r-- | prototypes/SplayList.hs | 8 | ||||
-rw-r--r-- | prototypes/Stream.hs | 5 |
4 files changed, 43 insertions, 0 deletions
diff --git a/prototypes/FreeVars.hs b/prototypes/FreeVars.hs index f0fb9a4b..32ad98a7 100644 --- a/prototypes/FreeVars.hs +++ b/prototypes/FreeVars.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | {-# LANGUAGE OverloadedStrings #-} | 2 | {-# LANGUAGE OverloadedStrings #-} |
2 | {-# LANGUAGE PatternSynonyms #-} | 3 | {-# LANGUAGE PatternSynonyms #-} |
3 | {-# LANGUAGE PatternGuards #-} | 4 | {-# LANGUAGE PatternGuards #-} |
@@ -74,7 +75,12 @@ instance Num Nat where | |||
74 | 75 | ||
75 | instance Monoid Nat where | 76 | instance Monoid Nat where |
76 | mempty = 0 | 77 | mempty = 0 |
78 | #if !MIN_VERSION_base(4,11,0) | ||
77 | Nat a `mappend` Nat b = Nat (a + b) | 79 | Nat a `mappend` Nat b = Nat (a + b) |
80 | #else | ||
81 | instance Semigroup Nat where | ||
82 | Nat a <> Nat b = Nat (a + b) | ||
83 | #endif | ||
78 | 84 | ||
79 | instance PShow Nat where pShow (Nat i) = pShow i | 85 | instance PShow Nat where pShow (Nat i) = pShow i |
80 | instance Show Nat where show = ppShow | 86 | instance Show Nat where show = ppShow |
@@ -157,6 +163,7 @@ fromStr = fromBools . map (=='1') | |||
157 | instance Monoid FV where | 163 | instance Monoid FV where |
158 | mempty = FE | 164 | mempty = FE |
159 | 165 | ||
166 | #if !MIN_VERSION_base(4,11,0) | ||
160 | mappend x FE = x | 167 | mappend x FE = x |
161 | mappend FE x = x | 168 | mappend FE x = x |
162 | mappend (FV a b us) (FV a' b' us') | 169 | mappend (FV a b us) (FV a' b' us') |
@@ -166,6 +173,18 @@ instance Monoid FV where | |||
166 | | otherwise = fv c (a' + b' - c) $ mappend (FV 0 ((a + b) - (a' + b')) us) us' | 173 | | otherwise = fv c (a' + b' - c) $ mappend (FV 0 ((a + b) - (a' + b')) us) us' |
167 | where | 174 | where |
168 | c = min a a' | 175 | c = min a a' |
176 | #else | ||
177 | instance Semigroup FV where | ||
178 | (<>) x FE = x | ||
179 | (<>) FE x = x | ||
180 | (<>) (FV a b us) (FV a' b' us') | ||
181 | | a + b <= a' = fv a b $ us <> (FV (a' - (a + b)) b' us') | ||
182 | | a + b - a' <= b' = fv c (a + b - c) $ us <> (FV 0 (b' - (a + b - a')) us') | ||
183 | | a' + b' <= a = fv a' b' $ (FV (a - (a' + b')) b us) <> us' | ||
184 | | otherwise = fv c (a' + b' - c) $ (FV 0 ((a + b) - (a' + b')) us) <> us' | ||
185 | where | ||
186 | c = min a a' | ||
187 | #endif | ||
169 | 188 | ||
170 | prop_monoid_FV = prop_Monoid (T :: T FV) | 189 | prop_monoid_FV = prop_Monoid (T :: T FV) |
171 | prop_mappend_normal_FV (a :: FV) b = testNormalFV (a <> b) | 190 | prop_mappend_normal_FV (a :: FV) b = testNormalFV (a <> b) |
@@ -335,7 +354,12 @@ instance Arbitrary SFV where | |||
335 | instance Monoid SFV where | 354 | instance Monoid SFV where |
336 | mempty = SFV 0 mempty | 355 | mempty = SFV 0 mempty |
337 | 356 | ||
357 | #if !MIN_VERSION_base(4,11,0) | ||
338 | SFV m b `mappend` SFV n a = SFV (n + m) $ sDrop n b <> a | 358 | SFV m b `mappend` SFV n a = SFV (n + m) $ sDrop n b <> a |
359 | #else | ||
360 | instance Semigroup SFV where | ||
361 | SFV m b <> SFV n a = SFV (n + m) $ sDrop n b <> a | ||
362 | #endif | ||
339 | 363 | ||
340 | prop_monoid_SFV = prop_Monoid (T :: T SFV) | 364 | prop_monoid_SFV = prop_Monoid (T :: T SFV) |
341 | {- | 365 | {- |
diff --git a/prototypes/LamMachineV2.hs b/prototypes/LamMachineV2.hs index 0d51d8a8..acacdf4b 100644 --- a/prototypes/LamMachineV2.hs +++ b/prototypes/LamMachineV2.hs | |||
@@ -3,6 +3,7 @@ | |||
3 | -- LamMachine is a variant of the machine described in | 3 | -- LamMachine is a variant of the machine described in |
4 | -- "Deriving a Lazy Abstract Machine" (1997) by Peter Sestoft | 4 | -- "Deriving a Lazy Abstract Machine" (1997) by Peter Sestoft |
5 | 5 | ||
6 | {-# LANGUAGE CPP #-} | ||
6 | {-# LANGUAGE OverloadedStrings #-} | 7 | {-# LANGUAGE OverloadedStrings #-} |
7 | {-# LANGUAGE PatternSynonyms #-} | 8 | {-# LANGUAGE PatternSynonyms #-} |
8 | {-# LANGUAGE PatternGuards #-} | 9 | {-# LANGUAGE PatternGuards #-} |
@@ -192,7 +193,12 @@ newtype MDB = MDB {getMDB :: Int} | |||
192 | 193 | ||
193 | instance Monoid MDB where | 194 | instance Monoid MDB where |
194 | mempty = MDB 0 | 195 | mempty = MDB 0 |
196 | #if !MIN_VERSION_base(4,11,0) | ||
195 | MDB n `mappend` MDB m = MDB $ n `max` m | 197 | MDB n `mappend` MDB m = MDB $ n `max` m |
198 | #else | ||
199 | instance Semigroup MDB where | ||
200 | MDB n <> MDB m = MDB $ n `max` m | ||
201 | #endif | ||
196 | 202 | ||
197 | ------------------------------------- rearrange De Bruijn indices | 203 | ------------------------------------- rearrange De Bruijn indices |
198 | 204 | ||
diff --git a/prototypes/SplayList.hs b/prototypes/SplayList.hs index 2cee0699..b2a8c743 100644 --- a/prototypes/SplayList.hs +++ b/prototypes/SplayList.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# LANGUAGE CPP #-} | ||
1 | {-# LANGUAGE FlexibleContexts #-} | 2 | {-# LANGUAGE FlexibleContexts #-} |
2 | {-# LANGUAGE FlexibleInstances #-} | 3 | {-# LANGUAGE FlexibleInstances #-} |
3 | {-# LANGUAGE UndecidableInstances #-} | 4 | {-# LANGUAGE UndecidableInstances #-} |
@@ -58,9 +59,16 @@ class (HasFV a, Measure a ~ Nat) => Measured a where | |||
58 | 59 | ||
59 | instance Measured a => Monoid (SplayList a) where | 60 | instance Measured a => Monoid (SplayList a) where |
60 | mempty = Nil | 61 | mempty = Nil |
62 | #if !MIN_VERSION_base(4,11,0) | ||
61 | Nil `mappend` ys = ys | 63 | Nil `mappend` ys = ys |
62 | xs `mappend` Nil = xs | 64 | xs `mappend` Nil = xs |
63 | xs `mappend` ys = Append xs ys | 65 | xs `mappend` ys = Append xs ys |
66 | #else | ||
67 | instance Semigroup (SplayList a) where | ||
68 | Nil <> ys = ys | ||
69 | xs <> Nil = xs | ||
70 | xs <> ys = Append xs ys | ||
71 | #endif | ||
64 | 72 | ||
65 | instance (Measured a, HasFV a) => HasFV (SplayList a) where | 73 | instance (Measured a, HasFV a) => HasFV (SplayList a) where |
66 | fvLens = \case | 74 | fvLens = \case |
diff --git a/prototypes/Stream.hs b/prototypes/Stream.hs index e848fe36..b887f1ad 100644 --- a/prototypes/Stream.hs +++ b/prototypes/Stream.hs | |||
@@ -139,7 +139,12 @@ dbAnd a b = not <$> sOr (not <$> a) (not <$> b) | |||
139 | 139 | ||
140 | instance Monoid (Stream Bool) where | 140 | instance Monoid (Stream Bool) where |
141 | mempty = Repeat False | 141 | mempty = Repeat False |
142 | #if !MIN_VERSION_base(4,11,0) | ||
142 | mappend = sOr | 143 | mappend = sOr |
144 | #else | ||
145 | instance Semigroup (Stream Bool) where | ||
146 | (<>) = sOr | ||
147 | #endif | ||
143 | 148 | ||
144 | prop_StreamBool_monoid_left (a :: Stream Bool) = mempty <> a == a | 149 | prop_StreamBool_monoid_left (a :: Stream Bool) = mempty <> a == a |
145 | prop_StreamBool_monoid_right (a :: Stream Bool) = a <> mempty == a | 150 | prop_StreamBool_monoid_right (a :: Stream Bool) = a <> mempty == a |