Note that there are some explanatory texts on larger screens.

plurals
  1. POAre there "type-level combinators"? Will they exist in some future?
    primarykey
    data
    text
    <p>Much of what makes haskell really nice to use in my opinion are combinators such as <code>(.)</code>, <code>flip</code>, <code>$</code> <code>&lt;*&gt;</code> and etc. It feels almost like I can create new syntax when I need to. </p> <p>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:</p> <pre><code>m :: * -&gt; * -&gt; * </code></pre> <p>and that I have a class <code>MyClass</code> that needs a type with a type constructor with kind <code>* -&gt; *</code>. Naturally I would choose to code the type in such a way that I can do:</p> <pre><code>instance MyClass (m a) </code></pre> <p>But suppose I can't change that code, and suppose that what really fits into <code>MyClass</code> is something like </p> <pre><code>type w b = m b a instance MyClass w where ... </code></pre> <p>and then I'd have to activate <code>XTypeSynonymInstances</code>. Is there some way to create a "type level combinator" <code>Flip</code> such that I can just do:</p> <pre><code>instance MyClass (Flip m a) where ... </code></pre> <p>?? Or other type level generalisations of common operators we use in haskell? Is this even useful or am I just rambling? </p> <p>Edit:</p> <p>I could do something like:</p> <pre><code>newtype Flip m a b = Flip (m b a) newtype Dot m w a = Dot m (w a) ... </code></pre> <p>But then I'd have to use the data constructors <code>Flip</code>, <code>Dot</code>, ... around for pattern matching and etc. Is it worth it?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload