|
1
|
+{-# LANGUAGE NoImplicitPrelude, PolyKinds, DataKinds, TypeFamilies,
|
|
2
|
+ UndecidableSuperClasses, RankNTypes, TypeOperators,
|
|
3
|
+ FlexibleContexts, TypeSynonymInstances, FlexibleInstances,
|
|
4
|
+ UndecidableInstances #-}
|
|
5
|
+module Monolith where
|
|
6
|
+
|
|
7
|
+import Data.Kind (Type)
|
|
8
|
+import GHC.Exts (Constraint)
|
|
9
|
+
|
|
10
|
+type family (~>) :: c -> c -> Type
|
|
11
|
+
|
|
12
|
+type instance (~>) = (->)
|
|
13
|
+type instance (~>) = ArrPair
|
|
14
|
+
|
|
15
|
+type family Fst (p :: (a, b)) :: a where
|
|
16
|
+ Fst '(x, _) = x
|
|
17
|
+
|
|
18
|
+type family Snd (p :: (a, b)) :: b where
|
|
19
|
+ Snd '(_, y) = y
|
|
20
|
+
|
|
21
|
+data ArrPair a b = ArrPair (Fst a ~> Fst b) (Snd a ~> Snd b)
|
|
22
|
+
|
|
23
|
+type family Super c :: Constraint where
|
|
24
|
+ Super Type = ()
|
|
25
|
+ Super (c, d) = (Category c, Category d)
|
|
26
|
+
|
|
27
|
+class Super cat => Category cat where
|
|
28
|
+ id :: forall (a :: cat). a ~> a
|
|
29
|
+
|
|
30
|
+instance Category Type where
|
|
31
|
+ id = \x -> x
|
|
32
|
+
|
|
33
|
+instance (Category c, Category d) => Category (c, d) where
|
|
34
|
+ id = ArrPair id id
|
|
35
|
+
|
|
36
|
+-- The commented out version worked
|
|
37
|
+-- class Category (c, d) => Functor (f :: c -> d) where
|
|
38
|
+class (Category c, Category d) => Functor (f :: c -> d) where
|
|
39
|
+ map :: (a ~> b) -> (f a ~> f b)
|
|
40
|
+
|
|
41
|
+data OnSnd f a b = OnSnd (f '(a, b))
|
|
42
|
+
|
|
43
|
+instance Functor (f :: (c, d) -> Type) => Functor (OnSnd f a) where
|
|
44
|
+ map f (OnSnd x) = OnSnd (map (ArrPair id f) x) |