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 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
|
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module TestBiBarbies
(
Record0(..)
, Record1(..)
, Record3(..)
, Record1S(..)
, Record3S(..)
, Ignore1(..)
, Sum3(..)
, CompositeRecord(..)
, SumRec(..)
, InfRec(..)
, NestedF(..)
, Nested2F(..)
, ParX(..)
, HKB(..)
, NestedB(..)
, MixedBT(..)
)
where
import Barbies
import Data.Distributive
import qualified TestBarbies
import Data.Kind(Type)
import Data.Typeable
import GHC.Generics
import Test.Tasty.QuickCheck
instance Arbitrary (b r l) => Arbitrary (Barbies.Flip b l r) where
arbitrary = Barbies.Flip <$> arbitrary
----------------------------------------------------
-- Product Barbies
----------------------------------------------------
data Record0 (f :: kl -> Type) (x :: kr)
= Record0
deriving
( Generic, Typeable
, Eq, Show
)
instance FunctorT Record0
instance DistributiveT Record0
instance ApplicativeT Record0
instance TraversableT Record0
instance ConstraintsT Record0
instance Arbitrary (Record0 f g) where arbitrary = pure Record0
data Record1 f (x :: kr)
= Record1 { rec1_f1 :: f Int }
deriving (Generic, Typeable)
instance FunctorT Record1
instance DistributiveT Record1
instance ApplicativeT Record1
instance TraversableT Record1
instance ConstraintsT Record1
deriving instance AllTF Show f Record1 => Show (Record1 f x)
deriving instance AllTF Eq f Record1 => Eq (Record1 f x)
instance AllTF Arbitrary f Record1 => Arbitrary (Record1 f g) where
arbitrary = Record1 <$> arbitrary
data Record1S f (x :: kr)
= Record1S { rec1s_f1 :: !(f Int) }
deriving (Generic, Typeable)
instance FunctorT Record1S
instance DistributiveT Record1S
instance ApplicativeT Record1S
instance TraversableT Record1S
instance ConstraintsT Record1S
deriving instance AllTF Show f Record1S => Show (Record1S f x)
deriving instance AllTF Eq f Record1S => Eq (Record1S f x)
instance AllTF Arbitrary f Record1S => Arbitrary (Record1S f x) where
arbitrary = Record1S <$> arbitrary
data Record3 f x
= Record3
{ rec3_f1 :: f Int
, rec3_f2 :: f Bool
, rec3_f3 :: f Char
, rec3_m1 :: Maybe ()
}
deriving (Generic, Typeable)
instance FunctorT Record3
instance ApplicativeT Record3
instance TraversableT Record3
instance ConstraintsT Record3
deriving instance AllTF Show f Record3 => Show (Record3 f x)
deriving instance AllTF Eq f Record3 => Eq (Record3 f x)
instance AllTF Arbitrary f Record3 => Arbitrary (Record3 f x) where
arbitrary = Record3 <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
data Record3S f x
= Record3S
{ rec3s_f1 :: !(f Int)
, rec3s_f2 :: !(f Bool)
, rec3s_f3 :: !(f Char)
}
deriving (Generic, Typeable)
instance FunctorT Record3S
instance DistributiveT Record3S
instance ApplicativeT Record3S
instance TraversableT Record3S
instance ConstraintsT Record3S
deriving instance AllTF Show f Record3S => Show (Record3S f x)
deriving instance AllTF Eq f Record3S => Eq (Record3S f x)
instance AllTF Arbitrary f Record3S => Arbitrary (Record3S f x) where
arbitrary = Record3S <$> arbitrary <*> arbitrary <*> arbitrary
-----------------------------------------------------
-- Bad products
-----------------------------------------------------
data Ignore1 (f :: Type -> Type) (x :: kx)
= Ignore1 { ign1_f1 :: Int }
deriving (Generic, Typeable, Eq, Show)
instance FunctorT Ignore1
instance TraversableT Ignore1
instance ConstraintsT Ignore1
instance Arbitrary (Ignore1 f x) where arbitrary = Ignore1 <$> arbitrary
-----------------------------------------------------
-- Sums
-----------------------------------------------------
data Sum3 f x
= Sum3_0
| Sum3_1 (f Int)
| Sum3_2 (f Int) (f Bool)
deriving (Generic, Typeable)
instance FunctorT Sum3
instance TraversableT Sum3
instance ConstraintsT Sum3
deriving instance AllTF Show f Sum3 => Show (Sum3 f x)
deriving instance AllTF Eq f Sum3 => Eq (Sum3 f x)
instance AllTF Arbitrary f Sum3 => Arbitrary (Sum3 f x) where
arbitrary
= oneof
[ pure Sum3_0
, Sum3_1 <$> arbitrary
, Sum3_2 <$> arbitrary <*> arbitrary
]
-----------------------------------------------------
-- Composite and recursive
-----------------------------------------------------
data CompositeRecord f x
= CompositeRecord
{ crec_f1 :: f Int
, crec_F2 :: f Bool
, crec_f3 :: Record3 f x
, crec_f4 :: Record1 f x
}
deriving (Generic, Typeable)
instance FunctorT CompositeRecord
instance ApplicativeT CompositeRecord
instance TraversableT CompositeRecord
instance ConstraintsT CompositeRecord
deriving instance AllTF Show f CompositeRecord => Show (CompositeRecord f x)
deriving instance AllTF Eq f CompositeRecord => Eq (CompositeRecord f x)
instance AllTF Arbitrary f CompositeRecord => Arbitrary (CompositeRecord f x) where
arbitrary
= CompositeRecord <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
data SumRec f x
= SumRec_0
| SumRec_1 (f Int)
| SumRec_2 (f Int) (SumRec f x)
deriving (Generic, Typeable)
instance FunctorT SumRec
instance TraversableT SumRec
instance ConstraintsT SumRec
deriving instance AllTF Show f SumRec => Show (SumRec f x)
deriving instance AllTF Eq f SumRec => Eq (SumRec f x)
instance AllTF Arbitrary f SumRec => Arbitrary (SumRec f x) where
arbitrary
= oneof
[ pure SumRec_0
, SumRec_1 <$> arbitrary
, SumRec_2 <$> arbitrary <*> arbitrary
]
data InfRec f x
= InfRec { ir_1 :: f Int, ir_2 :: InfRec f x }
deriving (Generic, Typeable)
instance FunctorT InfRec
instance ApplicativeT InfRec
instance TraversableT InfRec
instance ConstraintsT InfRec
deriving instance AllTF Show f InfRec => Show (InfRec f x)
deriving instance AllTF Eq f InfRec => Eq (InfRec f x)
-----------------------------------------------------
-- Nested under functors
-----------------------------------------------------
data NestedF f x
= NestedF
{ npf_1 :: f Int
, npf_2 :: [Record3 f x]
, npf_3 :: Maybe (NestedF f x)
}
deriving (Generic, Typeable)
instance FunctorT NestedF
instance ApplicativeT NestedF
instance TraversableT NestedF
deriving instance (Show (f Int), Show (Record3 f x)) => Show (NestedF f x)
deriving instance (Eq (f Int), Eq (Record3 f x)) => Eq (NestedF f x)
instance (Arbitrary (f Int), AllTF Arbitrary f Record3, AllTF Arbitrary f Sum3) => Arbitrary (NestedF f x) where
arbitrary
= scale (`div` 2) $
NestedF <$> arbitrary <*> scale (`div` 2) arbitrary <*> arbitrary
data Nested2F f x
= Nested2F
{ np2f_1 :: f Int
, np2f_2 :: [Maybe (Nested2F f x)]
}
deriving (Generic, Typeable)
instance FunctorT Nested2F
instance TraversableT Nested2F
instance ApplicativeT Nested2F
deriving instance Show (f Int) => Show (Nested2F f x)
deriving instance Eq (f Int) => Eq (Nested2F f x)
instance Arbitrary (f Int) => Arbitrary (Nested2F f x) where
arbitrary = scale (`div` 2) $ Nested2F <$> arbitrary <*> scale (`div` 2) arbitrary
-----------------------------------------------------
-- Parametric barbies
-----------------------------------------------------
data ParB b (f :: k -> Type) (x :: kx)
= ParB (b f x)
deriving (Generic, Typeable)
instance FunctorT b => FunctorT (ParB b)
instance DistributiveT b => DistributiveT (ParB b)
instance ApplicativeT b => ApplicativeT (ParB b)
instance TraversableT b => TraversableT (ParB b)
instance ConstraintsT b => ConstraintsT (ParB b)
data ParBH h b (f :: k -> Type) (x :: kx)
= ParBH (h (b f x))
deriving (Generic, Typeable)
instance (Functor h, FunctorT b) => FunctorT (ParBH h b)
instance (Distributive h, DistributiveT b) => DistributiveT (ParBH h b)
instance (Applicative h, ApplicativeT b) => ApplicativeT (ParBH h b)
instance (Traversable h, TraversableT b) => TraversableT (ParBH h b)
data ParX a f x
= ParX (f a) a
deriving (Generic, Typeable)
instance FunctorT (ParX a)
instance Monoid a => ApplicativeT (ParX a)
instance TraversableT (ParX a)
instance ConstraintsT (ParX a)
deriving instance (Show a, Show (f a)) => Show (ParX a f x)
deriving instance (Eq a, Eq (f a)) => Eq (ParX a f x)
instance (Arbitrary a, Arbitrary (f a)) => Arbitrary (ParX a f x) where
arbitrary
= ParX <$> arbitrary <*> arbitrary
-----------------------------------------------------
-- Higher-kinded barbies
-----------------------------------------------------
data HKB b x
= HKB
{ hkb1 :: b Maybe
, khb2 :: b ([])
}
deriving (Generic, Typeable)
instance FunctorT HKB
instance ApplicativeT HKB
instance TraversableT HKB
instance ConstraintsT HKB
-----------------------------------------------------
-- Actual bi-barbies
-----------------------------------------------------
type Record1' = TestBarbies.Record1
data NestedB f g
= NestedB
{ nb_1 :: g Int
, nb_2 :: f (g Bool)
, nb_3 :: f (Record1' g)
, nb_4 :: Record1' g
}
deriving (Generic, Typeable)
instance FunctorT NestedB
instance TraversableT NestedB
instance Functor f => FunctorB (NestedB f)
instance Distributive f => DistributiveB (NestedB f)
instance Applicative f => ApplicativeB (NestedB f)
instance Traversable f => TraversableB (NestedB f)
deriving instance (Show (f (g Bool)), AllBF Show g Record1', Show (f (Record1' g))) => Show (NestedB f g)
deriving instance (Eq (f (g Bool)), AllBF Eq g Record1', Eq (f (Record1' g))) => Eq (NestedB f g)
instance (Arbitrary (f (g Bool)), AllBF Arbitrary g Record1', Arbitrary (f (Record1' g))) => Arbitrary (NestedB f g) where
arbitrary
= NestedB <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
data MixedBT f g
= MixedBT
{ mx_1 :: f Int
, mx_2 :: g Bool
}
deriving (Generic, Typeable)
instance FunctorT MixedBT
instance TraversableT MixedBT
instance ConstraintsT MixedBT
instance FunctorB (MixedBT f)
instance (Monoid (f Int)) => ApplicativeB (MixedBT f)
instance TraversableB (MixedBT f)
instance ConstraintsB (MixedBT f)
deriving instance (AllBF Show g (MixedBT f), AllTF Show f MixedBT) => Show (MixedBT f g)
deriving instance (AllBF Eq g (MixedBT f), AllTF Eq f MixedBT) => Eq (MixedBT f g)
instance (AllBF Arbitrary g (MixedBT f), AllTF Arbitrary f MixedBT) => Arbitrary (MixedBT f g) where
arbitrary = MixedBT <$> arbitrary <*> arbitrary
|