on 0.11.2.0-r2 help sign in
40 lines 1.3 kB history raw
1{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE GADTs #-}
3{-# LANGUAGE TemplateHaskell #-}
4{-# LANGUAGE TypeFamilies #-}
5{-# OPTIONS_GHC -fno-warn-orphans #-}
7module DataFamilies.Instances where
9import Control.Applicative
10import Data.Aeson.TH
11import Data.Aeson.Types (FromJSON(..))
12import DataFamilies.Types
13import Test.QuickCheck (Arbitrary(..), elements, oneof)
14import Prelude
16instance (Arbitrary a) => Arbitrary (Approx a) where
17 arbitrary = Approx <$> arbitrary
19instance Arbitrary (Nullary Int) where
20 arbitrary = elements [C1, C2, C3]
22instance Arbitrary a => Arbitrary (SomeType c () a) where
23 arbitrary = oneof [ pure Nullary
24 , Unary <$> arbitrary
25 , Product <$> arbitrary <*> arbitrary <*> arbitrary
26 , Record <$> arbitrary <*> arbitrary <*> arbitrary
27 ]
29instance Arbitrary (GADT String) where
30 arbitrary = GADT <$> arbitrary
32deriveJSON defaultOptions 'C1
33deriveJSON defaultOptions 'Nullary
34deriveJSON defaultOptions 'Approx
36deriveToJSON defaultOptions 'GADT
37-- We must write the FromJSON instance head ourselves
38-- due to the refined GADT return type
39instance FromJSON (GADT String) where
40 parseJSON = $(mkParseJSON defaultOptions 'GADT)