/
TransformEntry.purs
30 lines (26 loc) · 994 Bytes
/
TransformEntry.purs
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
module LabeledData.TransformEntry where
import Data.Tuple.Nested (type (/\))
import Type.Proxy (Proxy(..))
class TransformEntry :: Type -> Symbol -> Symbol -> Type -> Type -> Constraint
class TransformEntry tok sym sym' a a' | tok sym a -> sym' a' where
transformEntry
:: Proxy tok -> Proxy sym -> Proxy sym' -> a -> a'
untransformEntry
:: Proxy tok -> Proxy sym' -> Proxy sym -> a' -> a
instance
( TransformEntry tokB sym sym' a a'
, TransformEntry tokA sym' sym'' a' a''
) =>
TransformEntry (tokA /\ tokB) sym sym'' a a'' where
transformEntry _ _ _ x =
let
x' :: a'
x' = transformEntry (Proxy :: _ tokB) (Proxy :: _ sym) (Proxy :: _ sym') x
in
transformEntry (Proxy :: _ tokA) (Proxy :: _ sym') (Proxy :: _ sym'') x'
untransformEntry _ _ _ x =
let
x' :: a'
x' = untransformEntry (Proxy :: _ tokA) (Proxy :: _ sym'') (Proxy :: _ sym') x
in
untransformEntry (Proxy :: _ tokB) (Proxy :: _ sym') (Proxy :: _ sym) x'