on 0.8.1.0 help sign in
70 lines 2.0 kB history raw
1{-# LANGUAGE CPP, DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
2#ifdef GHC_GENERICS
3{-# LANGUAGE DeriveGeneric, StandaloneDeriving #-}
4#endif
6module Types where
8import qualified Data.Map as Map
9import Data.Data
10import Data.Text
11#ifdef GHC_GENERICS
12import GHC.Generics
13#endif
15data Foo = Foo {
16 fooInt :: Int
17 , fooDouble :: Double
18 , fooTuple :: (String, Text, Int)
19 -- This definition causes an infinite loop in genericTo and genericFrom!
20 -- , fooMap :: Map.Map String Foo
21 , fooMap :: Map.Map String (Text,Int)
22 } deriving (Show, Typeable, Data)
24data UFoo = UFoo {
25 _UFooInt :: Int
26 , uFooInt :: Int
27 } deriving (Show, Eq, Data, Typeable)
29data OneConstructor = OneConstructor
30 deriving (Show, Eq, Typeable, Data)
32data Product2 a b = Product2 a b
33 deriving (Show, Eq, Typeable, Data)
35data Product6 a b c d e f = Product6 a b c d e f
36 deriving (Show, Eq, Typeable, Data)
38data Sum4 a b c d = Alt1 a | Alt2 b | Alt3 c | Alt4 d
39 deriving (Show, Eq, Typeable, Data)
41class ApproxEq a where
42 (=~) :: a -> a -> Bool
44newtype Approx a = Approx { fromApprox :: a }
45 deriving (Show, Data, Typeable, ApproxEq, Num)
47instance (ApproxEq a) => Eq (Approx a) where
48 Approx a == Approx b = a =~ b
50data Nullary = C1 | C2 | C3 deriving (Eq, Show)
52data SomeType a = Nullary
53 | Unary Int
54 | Product String (Maybe Char) a
55 | Record { testOne :: Double
56 , testTwo :: Maybe Bool
57 , testThree :: Maybe a
58 } deriving (Eq, Show)
60#ifdef GHC_GENERICS
61deriving instance Generic Foo
62deriving instance Generic UFoo
63deriving instance Generic OneConstructor
64deriving instance Generic (Product2 a b)
65deriving instance Generic (Product6 a b c d e f)
66deriving instance Generic (Sum4 a b c d)
67deriving instance Generic (Approx a)
68deriving instance Generic Nullary
69deriving instance Generic (SomeType a)
70#endif