<div dir="ltr"><div>Because you are not showing x or pi, you are showing (pi * x * x).  And the type of the (*) operator is (*) :: Num a => a -> a -> a.  So if pi is Floating => a, then x must also be the same type as pi, and thus must be have the same Floating constraint.<br><br>Keep in mind that Floating is a Fractional, and Fractional is a Num, so you know that if you have a Floating it is already an instance of Num, so you don't have to worry about that constraint.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 4, 2018 at 10:08 AM, 清羽 <span dir="ltr"><<a href="mailto:1625143974@qq.com" target="_blank">1625143974@qq.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>this is the original question:</div><ol style="box-sizing:border-box;margin-top:0px;margin-bottom:10px;color:rgb(51,51,51);font-family:-apple-system,'Helvetica Neue',Helvetica,Arial,sans-serif" type="1"><li style="box-sizing:border-box"><p style="box-sizing:border-box;margin:0px 0px 10px">Write a function <code class="m_5325923052921373922sourceCode m_5325923052921373922haskell" style="box-sizing:border-box;white-space:pre-wrap;font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:12.600000381469727px;padding:2px 4px;color:rgb(199,37,78);background-color:rgb(249,242,244);border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-right-radius:4px;border-bottom-left-radius:4px">showAreaOfCircle</code> <wbr>which, given the radius of a circle, calculates the area of the circle,</p><blockquote style="box-sizing:border-box;padding:10px 20px;margin:0px 0px 20px;font-size:17.5px;border-left-width:5px;border-left-style:solid;border-left-color:rgb(238,238,238)"><p style="box-sizing:border-box;margin:0px"><code class="m_5325923052921373922sourceCode m_5325923052921373922haskell" style="box-sizing:border-box;white-space:pre-wrap;font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:15.75px;padding:2px 4px;color:rgb(199,37,78);background-color:rgb(249,242,244);border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-right-radius:4px;border-bottom-left-radius:4px">showAreaOfCircle <span class="m_5325923052921373922fl" style="box-sizing:border-box;color:rgb(64,160,112)">12.3</span></code> <span class="m_5325923052921373922math m_5325923052921373922inline" style="box-sizing:border-box"> ⇒ </span><code class="m_5325923052921373922sourceCode m_5325923052921373922haskell" style="box-sizing:border-box;white-space:pre-wrap;font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:15.75px;padding:2px 4px;color:rgb(199,37,78);background-color:rgb(249,242,244);border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-right-radius:4px;border-bottom-left-radius:4px"><span class="m_5325923052921373922st" style="box-sizing:border-box;color:rgb(64,112,160)">"The area of a circle with radius 12.3cm is about  475.2915525615999 cm^2"</span></code></p></blockquote><p style="box-sizing:border-box;margin:0px 0px 10px">Use the <code class="m_5325923052921373922sourceCode m_5325923052921373922haskell" style="box-sizing:border-box;white-space:pre-wrap;font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:12.600000381469727px;padding:2px 4px;color:rgb(199,37,78);background-color:rgb(249,242,244);border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-right-radius:4px;border-bottom-left-radius:4px">show</code> function, as well as the predefined value <code class="m_5325923052921373922sourceCode m_5325923052921373922haskell" style="box-sizing:border-box;white-space:pre-wrap;font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:12.600000381469727px;padding:2px 4px;color:rgb(199,37,78);background-color:rgb(249,242,244);border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-right-radius:4px;border-bottom-left-radius:4px">pi<span class="m_5325923052921373922ot" style="box-sizing:border-box;color:rgb(0,112,32)"> ::</span> <span class="m_5325923052921373922dt" style="box-sizing:border-box;color:rgb(144,32,0)">Floating</span> a <span class="m_5325923052921373922ot" style="box-sizing:border-box;color:rgb(0,112,32)">=></span> a</code> to write <code class="m_5325923052921373922sourceCode m_5325923052921373922haskell" style="box-sizing:border-box;white-space:pre-wrap;font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:12.600000381469727px;padding:2px 4px;color:rgb(199,37,78);background-color:rgb(249,242,244);border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-right-radius:4px;border-bottom-left-radius:4px">showAreaOfCircle</code>.</p></li></ol><div><u></u></div><div>the type signature works for this function is: showAreaOfCircle :: (Show a, Floating a) => a -> a -> String</div><div><br></div><div>my question is :<span style="color:rgb(255,255,255);font-family:'Helvetica Neue','Segoe UI',Helvetica,Arial,sans-serif;font-size:15px;white-space:pre-wrap;background-color:rgb(0,132,255)"></span><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(238,238,238)"> </span><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:13px;background-color:rgb(238,238,238)">I don't quite understand the syntax behind the parenthesis and the type class Floating a. Since pi is not a function, and hence the entire function only takes one argument which belongs to the type class Show, why should i put a Floating a in the type signature in the first place?(i come up with this type signature because of the error message and the suggestion stated above) Thanks</span></div><div><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Menlo';font-size:9.0pt"><span style="color:#9876aa"></span></pre></div><br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>