summaryrefslogtreecommitdiff
path: root/testsuite/tests/deriving/should_compile/deriving-via-standalone.hs
blob: 26484a2df24c2189016253cb6ee782835faa52bb (plain)
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
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
module DerivingViaStandalone where

import Data.Kind (Type)
import Control.Applicative
import Data.Functor.Compose
import Data.Proxy
import Data.Semigroup

newtype App (f :: Type -> Type) a = App (f a)
  deriving newtype
    (Functor, Applicative)

instance (Applicative f, Semigroup a) => Semigroup (App f a) where
  (<>) = liftA2 (<>)

deriving via (App (Compose (f :: Type -> Type) g) a)
         instance (Applicative f, Applicative g, Semigroup a)
               => Semigroup (Compose f g a)

class C (a :: k -> Type)
instance C Proxy

newtype MyProxy a = MyProxy (Proxy a)
deriving via (Proxy :: Type -> Type) instance C MyProxy

class Z a b
data T a
data X1 a
data X2 a
data X3 a

deriving via (forall a. T a) instance           Z a (X1 b)
deriving via           (T a) instance forall b. Z a (X2 b)
deriving via (forall a. T a) instance forall b. Z a (X3 b)