on 1.0.1.0 help sign in
105 lines 3.0 kB history raw
1{-# LANGUAGE CPP #-}
2{-# LANGUAGE DeriveDataTypeable #-}
3{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE GADTs #-}
6{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7{-# LANGUAGE StandaloneDeriving #-}
9module Types where
11import Prelude ()
12import Prelude.Compat
14import Data.Data
15import Data.Functor.Compose (Compose (..))
16import Data.Functor.Identity (Identity (..))
17import Data.Text
18import GHC.Generics
19import Test.QuickCheck (Property, counterexample)
20import qualified Data.Map as Map
22type I = Identity
23type Compose3 f g h = Compose (Compose f g) h
24type Compose3' f g h = Compose f (Compose g h)
26data Foo = Foo {
27 fooInt :: Int
28 , fooDouble :: Double
29 , fooTuple :: (String, Text, Int)
30 -- This definition causes an infinite loop in genericTo and genericFrom!
31 -- , fooMap :: Map.Map String Foo
32 , fooMap :: Map.Map String (Text,Int)
33 } deriving (Show, Typeable, Data)
35data UFoo = UFoo {
36 _UFooInt :: Int
37 , uFooInt :: Int
38 } deriving (Show, Eq, Data, Typeable)
40data OneConstructor = OneConstructor
41 deriving (Show, Eq, Typeable, Data)
43data Product2 a b = Product2 a b
44 deriving (Show, Eq, Typeable, Data)
46data Product6 a b c d e f = Product6 a b c d e f
47 deriving (Show, Eq, Typeable, Data)
49data Sum4 a b c d = Alt1 a | Alt2 b | Alt3 c | Alt4 d
50 deriving (Show, Eq, Typeable, Data)
52class ApproxEq a where
53 (=~) :: a -> a -> Bool
55newtype Approx a = Approx { fromApprox :: a }
56 deriving (Show, Data, Typeable, ApproxEq, Num)
58instance (ApproxEq a) => Eq (Approx a) where
59 Approx a == Approx b = a =~ b
61data Nullary = C1 | C2 | C3 deriving (Eq, Show)
63data SomeType a = Nullary
64 | Unary Int
65 | Product String (Maybe Char) a
66 | Record { testOne :: Double
67 , testTwo :: Maybe Bool
68 , testThree :: Maybe a
69 }
70 | List [a]
71 deriving (Eq, Show)
73-- Used for testing UntaggedValue SumEncoding
74data EitherTextInt
75 = LeftBool Bool
76 | RightInt Int
77 | BothTextInt Text Int
78 | NoneNullary
79 deriving (Eq, Show)
81data GADT a where
82 GADT :: { gadt :: String } -> GADT String
83 deriving Typeable
85deriving instance Data (GADT String)
86deriving instance Eq (GADT a)
87deriving instance Show (GADT a)
89deriving instance Generic Foo
90deriving instance Generic UFoo
91deriving instance Generic OneConstructor
92deriving instance Generic (Product2 a b)
93deriving instance Generic (Product6 a b c d e f)
94deriving instance Generic (Sum4 a b c d)
95deriving instance Generic (Approx a)
96deriving instance Generic Nullary
97deriving instance Generic (SomeType a)
98#if __GLASGOW_HASKELL__ >= 706
99deriving instance Generic1 SomeType
100#endif
101deriving instance Generic EitherTextInt
103failure :: Show a => String -> String -> a -> Property
104failure func msg v = counterexample
105 (func ++ " failed: " ++ msg ++ ", " ++ show v) False