Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are three options here. The first option is to add</p> <pre><code>{-# LANGUAGE NoMonomorphismRestriction #-} </code></pre> <p>to the top of your module file.</p> <p>The second option is to add an explicit type signature to psqlDriver.</p> <pre><code>psqlDriver :: (Field field, Table table) =&gt; (table -&gt; [field] -&gt; String) -&gt; DatabaseDriver a b </code></pre> <p>The reason for all of this is a little nuanced, and more details can be found <a href="http://www.haskell.org/haskellwiki/Monomorphism_restriction" rel="nofollow">here</a></p> <p>The third option is to change the definition of <code>psqlDriver</code> to</p> <pre><code>psqlDriver = DatabaseDriver insert select </code></pre> <p>However, this is truly ambiguous - there is not reason to prefer any particular instance of <code>Table</code> or <code>Field</code> over another. Perhaps you mean to define <code>DatabaseDriver</code> as follows.</p> <pre><code>data DatabaseDriver table field where DatabaseDriver :: (Table table, Field field) =&gt; { dbInsert :: table -&gt; [field] -&gt; String , dbSelect :: table -&gt; [field] -&gt; String } -&gt; DatabaseDriver table field </code></pre> <p>If the original definition of <code>DatabaseDriver</code> is rewritten as an ADT, it is more obvious why.</p> <p>As it is currently written in the question, the translation to an ADT is</p> <pre><code>{-# LANGUAGE ExistentialQuantification #-} data DatabaseDriver a b = forall table field . (Table table, Field field) =&gt; DatabaseDriver { dbInsert :: table -&gt; [field] -&gt; String , dbSelect :: table -&gt; [field] -&gt; String } </code></pre> <p>Notice the nested <code>forall table field</code>, and how <code>table</code> and <code>field</code> have no relationship to <code>a</code> or <code>b</code>.</p> <p>The intended translation is either</p> <pre><code>data DatabaseDriver table field = (Table table, Field field) =&gt; DatabaseDriver { dbInsert :: table -&gt; [field] -&gt; String , dbSelect :: table -&gt; [field] -&gt; String } </code></pre> <p>or most likely</p> <pre><code>data DatabaseDriver table field = DatabaseDriver { dbInsert :: table -&gt; [field] -&gt; String , dbSelect :: table -&gt; [field] -&gt; String } </code></pre> <p>Having the type class constraints in the definition of <code>DatabaseDriver</code> does not let you remove the type class constraints from any use of <code>DatabaseDriver</code>, in particular <code>psqlDriver</code>. In both of the ADT translations above, the type of <code>psqlDriver</code> is</p> <pre><code>psqlDriver :: (Table table, Field field) =&gt; DatabaseDriver table field </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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