Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, your type signature is syntactically wrong (according to my reading of <a href="http://www.haskell.org/onlinereport/haskell2010/haskellch10.html#x17-18000010.5" rel="nofollow">the context-free syntax</a> in the report, although GHC accepts it), it should be</p> <pre><code>foo::(Num a, Num b) =&gt; a -&gt; b -&gt; Bool </code></pre> <p>Regarding the question, you can't do that, <code>(&lt;)</code> has type <code>Ord a =&gt; a -&gt; a -&gt; Bool</code>, so both arguments must have the same type.</p> <p>With a stronger restriction than just <code>Num</code>, you could for example have</p> <pre><code>bar :: (Real a, Real b) =&gt; a -&gt; b -&gt; Bool bar a b = toRational a &lt; toRational b </code></pre> <p>You need to be able to convert both arguments to the same target type (with a meaningful conversion) to compare the values. For types in the <code>Real</code> class, <code>toRational</code> provides such a conversion to a common target type (with the caveat that <code>toRational</code> doesn't work reasonably with NaNs and infinities if the starting type is a floating point type). <code>toInteger</code> would achieve the same for an <code>Integral</code> constraint.</p> <p>There is no such common target type available with just a <code>Num</code> constraint.</p> <p>For your special needs, you may be able to select a target type and define a</p> <pre><code>class Convertible a where toTarget :: a -&gt; Target </code></pre> <p>if <code>Real</code> or <code>Integral</code> are not viable constraints.</p>
    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