{-# Language PatternSynonyms #-}
{-# Language ViewPatterns #-}
data DMonad m = DMonad
(forall a. a -> m a)
(forall a b. m a -> (a -> m b) -> m b)
(forall a. String -> m a)
pattern Open :: (forall a. a -> [a]) -> (forall a a'. [a] -> (a -> [a']) -> [a']) -> (forall a. String -> [a]) -> xxx
Ticket #12001
.
pattern Singleton :: a -> NonEmpty a
pattern Singleton a <- (uncons -> (a, Nothing))
where Singleton a = a N.:| []
infixr 5 :|
This could be synthesised
type family Methods (cls :: Type -> Constraint) (a :: Type) = (res :: [Pair Symbol Type]) | res -> a
type instance Methods A a = '["a" :- a]
type instance Methods B b = '["b" :- (b -> b)]
type instance Methods C c = '["c" :- (c -> Int), "b" :- (c -> c), "a" :- c]
data Pair a b = a :- b
demoteMonoid :: (forall m. Monoid m => m) -> Semigroup m => Maybe m
demoteMonoid k = eval k where
eval :: MONOID m -> Semigroup m => Maybe m
eval = getOption . foldMap (Option . Just)
data MONOID a = NIL | SING a | MONOID a :<> MONOID a
deriving Foldable
instance Monoid (MONOID a) where
Idea from https://gist.github.com/Icelandjack/e1ddefb0d5a79617a81ee98c49fbbdc4
Works great for concrete types
data A = MkA
instance (Eq & Ord & Show & Arbitrary) A where
(==) :: A -> A -> Bool
MkA == MkA = True
Principle of identity expansion
Whenever some construction has a certain relationship to all constructions of the same kind within a category, it must, in particular, have this relationship to itself. Socrates’ dictum to “know thyself” is as important in category theory as it is in life. So whenever we encounter a universal construction we will see what we can learn about it by “probing it with itself”. In the case of a terminal object, this means choosing
X ≔ T
in the definition.Lemma 3.1.1.2 (identity expansion for terminals) If
T
is a terminal object then!(T) = id(T)
.
Lemma 3.1.4.2 (identity expansion for initials) If
S
is an initial object then¡(S) = id(S)
.
{-# Language InstanceSigs, ViewPatterns, TupleSections, GeneralizedNewtypeDeriving, TemplateHaskell, LambdaCase #-} | |
module D where | |
import Language.Haskell.TH | |
import Data.Coerce | |
deriveVia :: Name -> Name -> Name -> Q [Dec] | |
deriveVia className ty viaNewTy = do | |
a <- reify className |