1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
|
{-# OPTIONS_GHC -O0 #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module TestBarbiesW
( Record1W(..)
, Record3W(..)
, Record1WS(..)
, Record3WS(..)
, Sum3W(..)
, CompositeRecordW(..)
, SumRecW(..)
, InfRecW(..)
, NestedFW(..)
, Nested2FW(..)
)
where
import Data.Functor.Barbie
import Barbies.Bare
import Data.Kind(Type)
import Data.Typeable
import GHC.Generics
import Test.Tasty.QuickCheck
----------------------------------------------------
-- Product Barbies
----------------------------------------------------
data Record1W t f
= Record1W { rec1w_f1 :: Wear t f Int }
deriving (Generic, Typeable)
instance FunctorB (Record1W Bare)
instance FunctorB (Record1W Covered)
instance DistributiveB (Record1W Covered)
instance TraversableB (Record1W Covered)
instance ApplicativeB (Record1W Covered)
instance ConstraintsB (Record1W Bare)
instance ConstraintsB (Record1W Covered)
instance BareB Record1W
deriving instance AllB Show (Record1W Bare) => Show (Record1W Bare f)
deriving instance AllB Eq (Record1W Bare) => Eq (Record1W Bare f)
deriving instance AllBF Show f (Record1W Covered) => Show (Record1W Covered f)
deriving instance AllBF Eq f (Record1W Covered) => Eq (Record1W Covered f)
instance AllBF Arbitrary f (Record1W Covered) => Arbitrary (Record1W Covered f) where
arbitrary = Record1W <$> arbitrary
data Record1WS t f
= Record1WS { rec1ws_f1 :: !(Wear t f Int) }
deriving (Generic, Typeable)
instance FunctorB (Record1WS Bare)
instance FunctorB (Record1WS Covered)
instance DistributiveB (Record1WS Covered)
instance TraversableB (Record1WS Covered)
instance ApplicativeB (Record1WS Covered)
instance ConstraintsB (Record1WS Bare)
instance ConstraintsB (Record1WS Covered)
instance BareB Record1WS
deriving instance AllB Show (Record1WS Bare) => Show (Record1WS Bare f)
deriving instance AllB Eq (Record1WS Bare) => Eq (Record1WS Bare f)
deriving instance AllBF Show f (Record1WS Covered) => Show (Record1WS Covered f)
deriving instance AllBF Eq f (Record1WS Covered) => Eq (Record1WS Covered f)
instance AllBF Arbitrary f (Record1WS Covered) => Arbitrary (Record1WS Covered f) where
arbitrary = Record1WS <$> arbitrary
data Record3W t f
= Record3W
{ rec3w_f1 :: Wear t f Int
, rec3w_f2 :: Wear t f Bool
, rec3w_f3 :: Wear t f Char
}
deriving (Generic, Typeable)
instance FunctorB (Record3W Bare)
instance FunctorB (Record3W Covered)
instance DistributiveB (Record3W Covered)
instance TraversableB (Record3W Bare)
instance TraversableB (Record3W Covered)
instance ApplicativeB (Record3W Covered)
instance ConstraintsB (Record3W Bare)
instance ConstraintsB (Record3W Covered)
instance BareB Record3W
deriving instance AllB Show (Record3W Bare) => Show (Record3W Bare f)
deriving instance AllB Eq (Record3W Bare) => Eq (Record3W Bare f)
deriving instance AllBF Show f (Record3W Covered) => Show (Record3W Covered f)
deriving instance AllBF Eq f (Record3W Covered) => Eq (Record3W Covered f)
instance AllBF Arbitrary f (Record3W Covered) => Arbitrary (Record3W Covered f) where
arbitrary = Record3W <$> arbitrary <*> arbitrary <*> arbitrary
data Record3WS t f
= Record3WS
{ rec3ws_f1 :: !(Wear t f Int)
, rec3ws_f2 :: !(Wear t f Bool)
, rec3ws_f3 :: !(Wear t f Char)
}
deriving (Generic, Typeable)
instance FunctorB (Record3WS Bare)
instance FunctorB (Record3WS Covered)
instance DistributiveB (Record3WS Covered)
instance TraversableB (Record3WS Covered)
instance ApplicativeB (Record3WS Covered)
instance ConstraintsB (Record3WS Bare)
instance ConstraintsB (Record3WS Covered)
instance BareB Record3WS
deriving instance AllB Show (Record3WS Bare) => Show (Record3WS Bare f)
deriving instance AllB Eq (Record3WS Bare) => Eq (Record3WS Bare f)
deriving instance AllBF Show f (Record3WS Covered) => Show (Record3WS Covered f)
deriving instance AllBF Eq f (Record3WS Covered) => Eq (Record3WS Covered f)
instance AllBF Arbitrary f (Record3WS Covered) => Arbitrary (Record3WS Covered f) where
arbitrary = Record3WS <$> arbitrary <*> arbitrary <*> arbitrary
----------------------------------------------------
-- Sum Barbies
----------------------------------------------------
data Sum3W t f
= Sum3W_0
| Sum3W_1 (Wear t f Int)
| Sum3W_2 (Wear t f Int) (Wear t f Bool)
deriving (Generic, Typeable)
instance FunctorB (Sum3W Bare)
instance FunctorB (Sum3W Covered)
instance TraversableB (Sum3W Covered)
instance ConstraintsB (Sum3W Bare)
instance ConstraintsB (Sum3W Covered)
instance BareB Sum3W
deriving instance AllB Show (Sum3W Bare) => Show (Sum3W Bare f)
deriving instance AllB Eq (Sum3W Bare) => Eq (Sum3W Bare f)
deriving instance AllBF Show f (Sum3W Covered) => Show (Sum3W Covered f)
deriving instance AllBF Eq f (Sum3W Covered) => Eq (Sum3W Covered f)
instance AllBF Arbitrary f (Sum3W Covered) => Arbitrary (Sum3W Covered f) where
arbitrary
= oneof
[ pure Sum3W_0
, Sum3W_1 <$> arbitrary
, Sum3W_2 <$> arbitrary <*> arbitrary
]
-----------------------------------------------------
-- Composite and recursive
-----------------------------------------------------
data CompositeRecordW t f
= CompositeRecordW
{ crecw_f1 :: Wear t f Int
, crecw_F2 :: Wear t f Bool
, crecw_f3 :: Record3W t f
, crecw_f4 :: Record1W t f
}
deriving (Generic, Typeable)
instance FunctorB (CompositeRecordW Bare)
instance FunctorB (CompositeRecordW Covered)
instance DistributiveB (CompositeRecordW Covered)
instance TraversableB (CompositeRecordW Covered)
instance ApplicativeB (CompositeRecordW Covered)
instance ConstraintsB (CompositeRecordW Bare)
instance ConstraintsB (CompositeRecordW Covered)
instance BareB CompositeRecordW
deriving instance AllB Show (CompositeRecordW Bare) => Show (CompositeRecordW Bare f)
deriving instance AllB Eq (CompositeRecordW Bare) => Eq (CompositeRecordW Bare f)
deriving instance AllBF Show f (CompositeRecordW Covered) => Show (CompositeRecordW Covered f)
deriving instance AllBF Eq f (CompositeRecordW Covered) => Eq (CompositeRecordW Covered f)
instance AllBF Arbitrary f (CompositeRecordW Covered) => Arbitrary (CompositeRecordW Covered f) where
arbitrary
= CompositeRecordW <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
data SumRecW t f
= SumRecW_0
| SumRecW_1 (Wear t f Int)
| SumRecW_2 (Wear t f Int) (SumRecW t f)
deriving (Generic, Typeable)
instance FunctorB (SumRecW Bare)
instance FunctorB (SumRecW Covered)
instance TraversableB (SumRecW Covered)
instance ConstraintsB (SumRecW Bare)
instance ConstraintsB (SumRecW Covered)
instance BareB SumRecW
deriving instance AllB Show (SumRecW Bare) => Show (SumRecW Bare f)
deriving instance AllB Eq (SumRecW Bare) => Eq (SumRecW Bare f)
deriving instance AllBF Show f (SumRecW Covered) => Show (SumRecW Covered f)
deriving instance AllBF Eq f (SumRecW Covered) => Eq (SumRecW Covered f)
instance AllBF Arbitrary f (SumRecW Covered) => Arbitrary (SumRecW Covered f) where
arbitrary
= oneof
[ pure SumRecW_0
, SumRecW_1 <$> arbitrary
, SumRecW_2 <$> arbitrary <*> arbitrary
]
data InfRecW t f
= InfRecW { irw_1 :: Wear t f Int, irw_2 :: InfRecW t f }
deriving (Generic, Typeable)
instance FunctorB (InfRecW Bare)
instance FunctorB (InfRecW Covered)
instance DistributiveB (InfRecW Covered)
instance TraversableB (InfRecW Covered)
instance ApplicativeB (InfRecW Covered)
instance ConstraintsB (InfRecW Bare)
instance ConstraintsB (InfRecW Covered)
instance BareB InfRecW
deriving instance AllB Show (InfRecW Bare) => Show (InfRecW Bare f)
deriving instance AllB Eq (InfRecW Bare) => Eq (InfRecW Bare f)
deriving instance AllBF Show f (InfRecW Covered) => Show (InfRecW Covered f)
deriving instance AllBF Eq f (InfRecW Covered) => Eq (InfRecW Covered f)
-----------------------------------------------------
-- Nested under functors
-----------------------------------------------------
data NestedFW t f
= NestedFW
{ npfw_1 :: Wear t f Int
, npfw_2 :: [Record3W t f]
, npfw_4 :: Maybe (NestedFW t f)
}
deriving (Generic, Typeable)
instance FunctorB (NestedFW Bare)
instance FunctorB (NestedFW Covered)
instance TraversableB (NestedFW Bare)
instance TraversableB (NestedFW Covered)
instance ApplicativeB (NestedFW Covered)
instance BareB NestedFW
deriving instance Show (NestedFW Bare f)
deriving instance Eq (NestedFW Bare f)
deriving instance (Show (f Int), Show (Record3W Covered f)) => Show (NestedFW Covered f)
deriving instance (Eq (f Int), Eq (Record3W Covered f)) => Eq (NestedFW Covered f)
instance (Arbitrary (f Int), Arbitrary (f Bool), Arbitrary (f Char)) => Arbitrary (NestedFW Covered f) where
arbitrary
= scale (`div` 2) $
NestedFW <$> arbitrary <*> scale (`div` 2) arbitrary <*> arbitrary
data Nested2FW t f
= Nested2FW
{ np2fw_1 :: Wear t f Int
, np2fw_2 :: [Maybe (Nested2FW t f)]
}
deriving (Generic, Typeable)
instance FunctorB (Nested2FW Bare)
instance FunctorB (Nested2FW Covered)
instance TraversableB (Nested2FW Bare)
instance TraversableB (Nested2FW Covered)
instance ApplicativeB (Nested2FW Covered)
instance BareB Nested2FW
deriving instance Show (Nested2FW Bare f)
deriving instance Eq (Nested2FW Bare f)
deriving instance Show (f Int) => Show (Nested2FW Covered f)
deriving instance Eq (f Int) => Eq (Nested2FW Covered f)
instance Arbitrary (f Int) => Arbitrary (Nested2FW Covered f) where
arbitrary = scale (`div` 2) $ Nested2FW <$> arbitrary <*> scale (`div` 2) arbitrary
-----------------------------------------------------
-- Parametric barbies
-----------------------------------------------------
data ParBW b t (f :: Type -> Type)
= ParBW (b t f)
deriving (Generic, Typeable)
instance FunctorB (b t) => FunctorB (ParBW b t)
instance TraversableB (b t) => TraversableB (ParBW b t)
instance ApplicativeB (b t) => ApplicativeB (ParBW b t)
instance BareB b => BareB (ParBW b)
-- XXX GHC currently rejects deriving this one since it
-- gets stuck on the TagSelf type family and can't see this
-- is an "Other" case. It looks like a bug to me, since it
-- seems to have enough information to decide that it is the
-- `Other` case that should be picked (or in any case, I don't
-- quite see why this is not an issue when `b` doesn't have the
-- extra type parameter.
instance ConstraintsB (b t) => ConstraintsB (ParBW b t) where
type AllB c (ParBW b t) = AllB c (b t)
baddDicts (ParBW btf) = ParBW (baddDicts btf)
data ParBHW h b t (f :: Type -> Type)
= ParBHW (h (b t f))
deriving (Generic, Typeable)
instance (Functor h, FunctorB (b t)) => FunctorB (ParBHW h b t)
instance (Traversable h, TraversableB (b t)) => TraversableB (ParBHW h b t)
instance (Applicative h, ApplicativeB (b t)) => ApplicativeB (ParBHW h b t)
instance (Functor h, BareB b) => BareB (ParBHW h b)
data ParXW a t f
= ParXW (Wear t f a)
deriving (Generic, Typeable)
instance FunctorB (ParXW a Bare)
instance FunctorB (ParXW a Covered)
instance DistributiveB (ParXW a Covered)
instance TraversableB (ParXW a Covered)
instance ApplicativeB (ParXW a Covered)
instance ConstraintsB (ParXW a Covered)
|