forked from haskell/aeson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypes.hs
81 lines (64 loc) · 2.38 KB
/
Types.hs
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
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StandaloneDeriving #-}
module Types where
import qualified Data.Map as Map
import Data.Data
import Data.Text
import GHC.Generics
import Test.QuickCheck (Property, counterexample)
data Foo = Foo {
fooInt :: Int
, fooDouble :: Double
, fooTuple :: (String, Text, Int)
-- This definition causes an infinite loop in genericTo and genericFrom!
-- , fooMap :: Map.Map String Foo
, fooMap :: Map.Map String (Text,Int)
} deriving (Show, Typeable, Data)
data UFoo = UFoo {
_UFooInt :: Int
, uFooInt :: Int
} deriving (Show, Eq, Data, Typeable)
data OneConstructor = OneConstructor
deriving (Show, Eq, Typeable, Data)
data Product2 a b = Product2 a b
deriving (Show, Eq, Typeable, Data)
data Product6 a b c d e f = Product6 a b c d e f
deriving (Show, Eq, Typeable, Data)
data Sum4 a b c d = Alt1 a | Alt2 b | Alt3 c | Alt4 d
deriving (Show, Eq, Typeable, Data)
class ApproxEq a where
(=~) :: a -> a -> Bool
newtype Approx a = Approx { fromApprox :: a }
deriving (Show, Data, Typeable, ApproxEq, Num)
instance (ApproxEq a) => Eq (Approx a) where
Approx a == Approx b = a =~ b
data Nullary = C1 | C2 | C3 deriving (Eq, Show)
data SomeType a = Nullary
| Unary Int
| Product String (Maybe Char) a
| Record { testOne :: Double
, testTwo :: Maybe Bool
, testThree :: Maybe a
} deriving (Eq, Show)
data GADT a where
GADT :: { gadt :: String } -> GADT String
deriving Typeable
deriving instance Data (GADT String)
deriving instance Eq (GADT a)
deriving instance Show (GADT a)
deriving instance Generic Foo
deriving instance Generic UFoo
deriving instance Generic OneConstructor
deriving instance Generic (Product2 a b)
deriving instance Generic (Product6 a b c d e f)
deriving instance Generic (Sum4 a b c d)
deriving instance Generic (Approx a)
deriving instance Generic Nullary
deriving instance Generic (SomeType a)
failure :: Show a => String -> String -> a -> Property
failure func msg v = counterexample
(func ++ " failed: " ++ msg ++ ", " ++ show v) False