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
|
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-|
Module: Derived.PolyKinds
Copyright: (C) 2014-2017 Ryan Scott
License: BSD-style (see the file LICENSE)
Maintainer: Ryan Scott
Stability: Provisional
Portability: GHC
Defines data types with poly-kinded type variables.
-}
module Derived.PolyKinds (
TyConCompose(..)
, TyConProxy(..)
, TyConReallyHighKinds
, TyFamilyCompose(..)
, TyFamilyProxy(..)
, TyFamilyReallyHighKinds(..)
) where
#include "generic.h"
import Data.Functor.Classes (Show1(..))
import Data.Orphans ()
import Generics.Deriving.Base
#if !defined(__LANGUAGE_DERIVE_GENERIC1__)
import qualified Generics.Deriving.TH as Generics
#endif
import Test.QuickCheck (Arbitrary)
import Text.Show.Deriving (deriveShow1)
import TextShow (TextShow(..), TextShow1(..), TextShow2(..))
import TextShow.TH (deriveTextShow2, makeShowbPrec,
makeLiftShowbPrec, makeLiftShowbPrec2)
#if defined(NEW_FUNCTOR_CLASSES)
import Data.Functor.Classes (Show2(..))
import Text.Show.Deriving (deriveShow2, makeLiftShowsPrec, makeLiftShowsPrec2)
#else
import Text.Show.Deriving (makeShowsPrec1)
#endif
-------------------------------------------------------------------------------
-- NB: Don't use k as a type variable here! It'll trigger GHC Trac #12503.
newtype TyConCompose f g h j p a b =
TyConCompose (f (g (j a) (p a)) (h (j a) (p b)))
deriving Generic
deriving instance Arbitrary (f (g (j a) (k a)) (h (j a) (k b))) =>
Arbitrary (TyConCompose f g h j k a b)
#if defined(__LANGUAGE_DERIVE_GENERIC1__)
deriving instance ( Functor (f (g (j a) (k a)))
, Functor (h (j a))
) => Generic1 (TyConCompose f g h j k a)
#endif
deriving instance Show (f (g (j a) (k a)) (h (j a) (k b))) =>
Show (TyConCompose f g h j k a b)
-------------------------------------------------------------------------------
newtype TyConProxy a b where
TyConProxy :: () -> TyConProxy a b
deriving ( Arbitrary
, Show
, Generic
#if defined(__LANGUAGE_DERIVE_GENERIC1__)
, Generic1
#endif
)
-------------------------------------------------------------------------------
newtype TyConReallyHighKinds f a b c d e = TyConReallyHighKinds (f a b c d e)
deriving ( Arbitrary
, Show
, Generic
#if defined(__LANGUAGE_DERIVE_GENERIC1__)
, Generic1
#endif
)
-------------------------------------------------------------------------------
data family TyFamilyCompose
(t :: k1 -> k2 -> *)
(u :: k3 -> k4 -> k1)
(v :: k3 -> k4 -> k2)
(w :: k5 -> k3)
(x :: k5 -> k4)
(y :: k5)
(z :: k5) :: *
newtype instance TyFamilyCompose f g h j k a b =
TyFamilyCompose (f (g (j a) (k a)) (h (j a) (k b)))
deriving Generic
deriving instance Arbitrary (f (g (j a) (k a)) (h (j a) (k b))) =>
Arbitrary (TyFamilyCompose f g h j k a b)
#if defined(__LANGUAGE_DERIVE_GENERIC1__)
deriving instance ( Functor (f (g (j a) (k a)))
, Functor (h (j a))
) => Generic1 (TyFamilyCompose f g h j k a)
#endif
deriving instance Show (f (g (j a) (k a)) (h (j a) (k b))) =>
Show (TyFamilyCompose f g h j k a b)
-------------------------------------------------------------------------------
data family TyFamilyProxy (x :: k1) (y :: k2) :: *
newtype instance TyFamilyProxy a b where
TyFamilyProxy :: () -> TyFamilyProxy a b
deriving ( Arbitrary
, Show
, Generic
#if defined(__LANGUAGE_DERIVE_GENERIC1__)
, Generic1
#endif
)
-------------------------------------------------------------------------------
data family TyFamilyReallyHighKinds
(g :: k1 -> k2 -> k3 -> k4 -> k5 -> *)
(v :: k1)
(w :: k2)
(x :: k3)
(y :: k4)
(z :: k5) :: *
newtype instance TyFamilyReallyHighKinds f a b c d e =
TyFamilyReallyHighKinds (f a b c d e)
deriving ( Arbitrary
, Show
, Generic
#if defined(__LANGUAGE_DERIVE_GENERIC1__)
, Generic1
#endif
)
-------------------------------------------------------------------------------
$(return [])
-- TODO: Replace these with non-orphan instances
$(deriveShow1 ''(,,,,))
#if defined(NEW_FUNCTOR_CLASSES)
$(deriveShow2 ''(,,,,))
#endif
#if defined(NEW_FUNCTOR_CLASSES)
instance (Show1 (f (g (j a) (k a))), Show1 (h (j a)), Show1 k) =>
Show1 (TyConCompose f g h j k a) where
liftShowsPrec = $(makeLiftShowsPrec ''TyConCompose)
instance (Show2 f, Show2 g, Show2 h, Show1 j, Show1 k) =>
Show2 (TyConCompose f g h j k) where
liftShowsPrec2 = $(makeLiftShowsPrec2 ''TyConCompose)
instance Show1 (TyConProxy (a :: *)) where
liftShowsPrec = $(makeLiftShowsPrec ''TyConProxy)
instance Show2 TyConProxy where
liftShowsPrec2 = $(makeLiftShowsPrec2 ''TyConProxy)
instance Show1 (f a b c d) => Show1 (TyConReallyHighKinds f a b c d) where
liftShowsPrec = $(makeLiftShowsPrec ''TyConReallyHighKinds)
instance Show2 (f a b c) => Show2 (TyConReallyHighKinds f a b c) where
liftShowsPrec2 = $(makeLiftShowsPrec2 ''TyConReallyHighKinds)
#else
instance (Functor (f (g (j a) (k a))), Functor (h (j a)),
Show1 (f (g (j a) (k a))), Show1 (h (j a)), Show1 k) =>
Show1 (TyConCompose f g h j k a) where
showsPrec1 = $(makeShowsPrec1 ''TyConCompose)
instance Show1 (TyConProxy (a :: *)) where
showsPrec1 = $(makeShowsPrec1 ''TyConProxy)
instance Show1 (f a b c d) => Show1 (TyConReallyHighKinds f a b c d) where
showsPrec1 = $(makeShowsPrec1 ''TyConReallyHighKinds)
#endif
instance TextShow (f (g (j a) (k a)) (h (j a) (k b))) =>
TextShow (TyConCompose f g h j k a b) where
showbPrec = $(makeShowbPrec ''TyConCompose)
instance (TextShow1 (f (g (j a) (k a))), TextShow1 (h (j a)), TextShow1 k) =>
TextShow1 (TyConCompose f g h j k a) where
liftShowbPrec = $(makeLiftShowbPrec ''TyConCompose)
$(deriveTextShow2 ''TyConCompose)
instance TextShow (TyConProxy a b) where
showbPrec = $(makeShowbPrec ''TyConProxy)
instance TextShow1 (TyConProxy a) where
liftShowbPrec = $(makeLiftShowbPrec ''TyConProxy)
$(deriveTextShow2 ''TyConProxy)
instance TextShow (f a b c d e) => TextShow (TyConReallyHighKinds f a b c d e) where
showbPrec = $(makeShowbPrec ''TyConReallyHighKinds)
instance TextShow1 (f a b c d) => TextShow1 (TyConReallyHighKinds f a b c d) where
liftShowbPrec = $(makeLiftShowbPrec ''TyConReallyHighKinds)
instance TextShow2 (f a b c) => TextShow2 (TyConReallyHighKinds f a b c) where
liftShowbPrec2 = $(makeLiftShowbPrec2 ''TyConReallyHighKinds)
#if !defined(__LANGUAGE_DERIVE_GENERIC1__)
$(Generics.deriveMeta ''TyConCompose)
$(Generics.deriveRep1Options False ''TyConCompose)
instance ( Functor (f (g (j a) (k a)))
, Functor (h (j a))
) => Generic1 (TyConCompose f g h j k a) where
type Rep1 (TyConCompose f g h j k a) = $(Generics.makeRep1 ''TyConCompose) f g h j k a
from1 = $(Generics.makeFrom1 ''TyConCompose)
to1 = $(Generics.makeTo1 ''TyConCompose)
$(Generics.deriveMeta ''TyConProxy)
$(Generics.deriveRepresentable1 ''TyConProxy)
$(Generics.deriveMeta ''TyConReallyHighKinds)
$(Generics.deriveRepresentable1 ''TyConReallyHighKinds)
#endif
#if !defined(NEW_FUNCTOR_CLASSES)
instance (Functor (f (g (j a) (k a))), Functor (h (j a)),
Show1 (f (g (j a) (k a))), Show1 (h (j a)), Show1 k) =>
Show1 (TyFamilyCompose f g h j k a) where
showsPrec1 = $(makeShowsPrec1 'TyFamilyCompose)
instance Show1 (TyFamilyProxy (a :: *)) where
showsPrec1 = $(makeShowsPrec1 'TyFamilyProxy)
instance Show1 (f a b c d) => Show1 (TyFamilyReallyHighKinds f a b c d) where
showsPrec1 = $(makeShowsPrec1 'TyFamilyReallyHighKinds)
#else
instance (Show1 (f (g (j a) (k a))), Show1 (h (j a)), Show1 k) =>
Show1 (TyFamilyCompose f g h j k a) where
liftShowsPrec = $(makeLiftShowsPrec 'TyFamilyCompose)
instance Show1 (TyFamilyProxy (a :: *)) where
liftShowsPrec = $(makeLiftShowsPrec 'TyFamilyProxy)
instance Show1 (f a b c d) => Show1 (TyFamilyReallyHighKinds f a b c d) where
liftShowsPrec = $(makeLiftShowsPrec 'TyFamilyReallyHighKinds)
instance (Show2 f, Show2 g, Show2 h, Show1 j, Show1 k) =>
Show2 (TyFamilyCompose f g h j k) where
liftShowsPrec2 = $(makeLiftShowsPrec2 'TyFamilyCompose)
instance Show2 TyFamilyProxy where
liftShowsPrec2 = $(makeLiftShowsPrec2 'TyFamilyProxy)
instance Show2 (f a b c) => Show2 (TyFamilyReallyHighKinds f a b c) where
liftShowsPrec2 = $(makeLiftShowsPrec2 'TyFamilyReallyHighKinds)
#endif
instance TextShow (f (g (j a) (k a)) (h (j a) (k b))) =>
TextShow (TyFamilyCompose f g h j k a b) where
showbPrec = $(makeShowbPrec 'TyFamilyCompose)
instance (TextShow1 (f (g (j a) (k a))), TextShow1 (h (j a)), TextShow1 k) =>
TextShow1 (TyFamilyCompose f g h j k a) where
liftShowbPrec = $(makeLiftShowbPrec 'TyFamilyCompose)
$(deriveTextShow2 'TyFamilyCompose)
instance TextShow (TyFamilyProxy a b) where
showbPrec = $(makeShowbPrec 'TyFamilyProxy)
instance TextShow1 (TyFamilyProxy a) where
liftShowbPrec = $(makeLiftShowbPrec 'TyFamilyProxy)
$(deriveTextShow2 'TyFamilyProxy)
instance TextShow (f a b c d e) => TextShow (TyFamilyReallyHighKinds f a b c d e) where
showbPrec = $(makeShowbPrec 'TyFamilyReallyHighKinds)
instance TextShow1 (f a b c d) => TextShow1 (TyFamilyReallyHighKinds f a b c d) where
liftShowbPrec = $(makeLiftShowbPrec 'TyFamilyReallyHighKinds)
instance TextShow2 (f a b c) => TextShow2 (TyFamilyReallyHighKinds f a b c) where
liftShowbPrec2 = $(makeLiftShowbPrec2 'TyFamilyReallyHighKinds)
#if !defined(__LANGUAGE_DERIVE_GENERIC1__)
$(Generics.deriveMeta 'TyFamilyCompose)
$(Generics.deriveRep1Options False 'TyFamilyCompose)
instance ( Functor (f (g (j a) (k a)))
, Functor (h (j a))
) => Generic1 (TyFamilyCompose f g h j k a) where
type Rep1 (TyFamilyCompose f g h j k a) = $(Generics.makeRep1 'TyFamilyCompose) f g h j k a
from1 = $(Generics.makeFrom1 'TyFamilyCompose)
to1 = $(Generics.makeTo1 'TyFamilyCompose)
$(Generics.deriveMeta 'TyFamilyProxy)
$(Generics.deriveRepresentable1 'TyFamilyProxy)
$(Generics.deriveMeta 'TyFamilyReallyHighKinds)
$(Generics.deriveRepresentable1 'TyFamilyReallyHighKinds)
#endif
|