Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  回复:  I have a question in designing a 'show'function
      (=?utf-8?B?5riF5769?=)


----------------------------------------------------------------------

Message: 1
Date: Wed, 4 Apr 2018 20:14:57 +0800
From: "=?utf-8?B?5riF5769?=" <1625143...@qq.com>
To:
        
"=?utf-8?B?VGhlIEhhc2tlbGwtQmVnaW5uZXJzIE1haWxpbmcgTGlzdCAtIERpc2N1c3Npb24gb2YgcHJpbWFyaWx5YmVnaW5uZXItbGV2ZWwgdG9waWNzIHJlbGF0ZWQgdG8gSGFza2VsbA==?="
 
        <beginners@haskell.org>
Subject: [Haskell-beginners] 回复:  I have a question in designing
        a 'show'function
Message-ID: <tencent_f9d317fdce21032ff4df2c33492d29496...@qq.com>
Content-Type: text/plain; charset="utf-8"

Yes.And I finally make the function error-free.Thanks


------------------ 原始邮件 ------------------
发件人: "Joel Neely"<joel.ne...@gmail.com>;
发送时间: 2018年4月4日(星期三) 晚上7:19
收件人: "The Haskell-Beginners Mailing List - Discussion of 
primarilybeginner-level topics related to Haskell"<beginners@haskell.org>;

主题: Re: [Haskell-beginners] I have a question in designing a 'show'function



You only have a single plus sign before the second invocation of show:


++ " " + show(pi * x * x) ++ "cm^2"Don't you mean concatenation?


++ " " ++ show(pi * x * x) ++ "cm^2"

Good luck,
-jn-




On Wed, Apr 4, 2018 at 1:37 AM, 清羽 <1625143...@qq.com> wrote:


here is the question:

Write a function showAreaOfCircle which, given the radius of a circle, 
calculates the area of the circle,
<code>showAreaOfCircle 12.3</code>  ⇒ <code>"The area of a circle with radius 
12.3cm is about 475.2915525615999 cm^2"</code>
my solution is:
showAreaOfCircle :: Show a => a -> String showAreaOfCircle x = "The area of a 
circle with radius" ++ show x ++ "is about" ++ " " + show(pi * x * x) ++ "cm^2"
but there is an error

• Could not deduce (Num a) arising from a use of ‘*’
from the context: Show a
bound by the type signature for:
showAreaOfCircle :: forall a. Show a => a -> String
at FirstStep.hs:20:1-41
Possible fix:
add (Num a) to the context of 
the type signature for:
showAreaOfCircle :: forall a. Show a => a -> String
• In the first argument of ‘show’, namely ‘(pi * x * x)’
In the second argument of ‘(+)’, namely ‘show (pi * x * x)’
In the second argument of ‘(++)’, namely ‘" " + show (pi * x * x)’

I had tried to change the type declaration to 
Show a => Num a => a -> String
i guess there must be a problem with pi.

Can someone help me with the error message? Great thanks


_______________________________________________
 Beginners mailing list
 Beginners@haskell.org
 http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
 





-- 
Beauty of style and harmony and grace and good rhythm depend on simplicity. - 
Plato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180404/16f21435/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 118, Issue 3
*****************************************

Reply via email to