summaryrefslogtreecommitdiff
path: root/testsuite/tests/generics/T10604/T10604_Authenticated.hs
blob: b43c11b58104fda09d3dedc5d1763de57906cfb0 (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
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
module T10604_Authenticated where

import GHC.Generics

data AuthParam = Prover | Verifier

class MapAuth f where
    mapAuth :: f 'Prover -> f 'Verifier
    default mapAuth :: (GMapAuth (Rep1 f), Generic1 f)
                    => f 'Prover -> f 'Verifier
    mapAuth = to1 . gmapAuth . from1

class GMapAuth f where
    gmapAuth :: f 'Prover -> f 'Verifier

instance GMapAuth V1 where
    gmapAuth = undefined

instance GMapAuth U1 where
    gmapAuth U1 = U1

instance (GMapAuth l, GMapAuth r) => GMapAuth (l :+: r) where
    gmapAuth (L1 x) = L1 (gmapAuth x)
    gmapAuth (R1 x) = R1 (gmapAuth x)

instance (GMapAuth l, GMapAuth r) => GMapAuth (l :*: r) where
    gmapAuth (x :*: y) = gmapAuth x :*: gmapAuth y

instance GMapAuth (K1 i c) where
    gmapAuth (K1 c) = K1 c

instance (GMapAuth f) => GMapAuth (M1 i t f) where
    gmapAuth (M1 x) = M1 (gmapAuth x)

instance (MapAuth f) => GMapAuth (Rec1 f) where
    gmapAuth (Rec1 x) = Rec1 (mapAuth x)