Much of what makes haskell really nice to use in my opinion are combinators such as (.)
, flip
, $
<*>
and etc. It feels almost like I can create new syntax when I need to.
Some time ago I was doing something where it would be tremendously convenient if I could "flip" a type constructor. Suppose I have some type constructor:
m :: * -> * -> *
and that I have a class MyClass
that needs a type with a type constructor with kind * -> *
. Naturally I would choose to code the type in such a way that I can do:
instance MyClass (m a)
But suppose I can't change that code, and suppose that what really fits into MyClass
is something like
type w b = m b a
instance MyClass w where
...
and then I'd have to activate XTypeSynonymInstances
. Is there some way to create a "type level combinator" Flip
such that I can just do:
instance MyClass (Flip m a) where
...
?? Or other type level generalisations of common operators we use in haskell? Is this even useful or am I just rambling?
Edit:
I could do something like:
newtype Flip m a b = Flip (m b a)
newtype Dot m w a = Dot m (w a)
...
But then I'd have to use the data constructors Flip
, Dot
, ... around for pattern matching and etc. Is it worth it?