Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Seeing <code>Floating a</code> and <code>Integral a</code> in a type signature together always sets off my internal alarm bells, as these classes are supposed to be mutually exclusive - at least, there are no standard numeric types that are instances of both classes. GHCi tells me (along with a lot of other stuff):</p> <pre><code>&gt; :info Integral ... instance Integral Integer -- Defined in `GHC.Real' instance Integral Int -- Defined in `GHC.Real' &gt; :info Floating ... instance Floating Float -- Defined in `GHC.Float' instance Floating Double -- Defined in `GHC.Float' </code></pre> <p>To see why these classes are mutually exclusive, let's have a look at some of the methods in both classes (this is going to be a bit handwavy). <code>fromInteger</code> in <code>Integral</code> converts an <code>Integral</code> number to an <code>Integer</code>, without loss of precision. In a way, <code>Integral</code> captures the essence of being (a subset of) the mathematical integers.</p> <p>On the other hand, <code>Floating</code> contains methods such as <code>pi</code> and <code>exp</code>, which have a pronounced 'real number' flavour. </p> <p>If there were a type that was both <code>Floating</code> and <code>Integral</code>, you could write <code>toInteger pi</code> and have a integer that was equal to 3.14159... - and that's not possible :-)</p> <hr> <p>That said, you should change all your type signatures to use <code>Double</code> instead of <code>Int</code>; after all, not all triangles have integer sides, or angles that are an integral number of degrees!</p> <p>If you <em>absolutely</em> don't want that for whatever reason, you also need to convert the sides (the <code>a</code> and <code>b</code> arguments) in <code>lawOfCosines</code> to <code>Double</code>. That's possible via</p> <pre><code>lawOfCosines aInt bInt gamma = sqrt $ a*a + b*b - 2*a*b*(cos (toRadians gamma)) where a = fromInteger aInt b = fromInteger bInt </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. 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