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. A question regarding the syntax behind the parenthesis and type class. (=?utf-8?B?5riF5769?=) 2. Re: A question regarding the syntax behind the parenthesis and type class. (David McBride) ---------------------------------------------------------------------- Message: 1 Date: Wed, 4 Apr 2018 22:08:04 +0800 From: "=?utf-8?B?5riF5769?=" <1625143...@qq.com> To: "=?utf-8?B?SGFza2VsbOmXruetlA==?=" <beginners@haskell.org> Subject: [Haskell-beginners] A question regarding the syntax behind the parenthesis and type class. Message-ID: <tencent_7d0f03a1f41b2d2d487d299b6a0f17cbc...@qq.com> Content-Type: text/plain; charset="utf-8" this is the original question: Write a function showAreaOfCircle which, given the radius of a circle, calculates the area of the circle, showAreaOfCircle 12.3 ⇒ "The area of a circle with radius 12.3cm is about 475.2915525615999 cm^2" Use the show function, as well as the predefined value pi :: Floating a => a to write showAreaOfCircle. the type signature works for this function is: showAreaOfCircle :: (Show a, Floating a) => a -> a -> String my question is : 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180404/a9509ebf/attachment-0001.html> ------------------------------ Message: 2 Date: Wed, 4 Apr 2018 10:20:40 -0400 From: David McBride <toa...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] A question regarding the syntax behind the parenthesis and type class. Message-ID: <can+tr4277p43qza9fifljyd1yvvj3khjqinferk2xm--gpd...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" 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. 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. On Wed, Apr 4, 2018 at 10:08 AM, 清羽 <1625143...@qq.com> wrote: > this is the original question: > > 1. > > Write a function showAreaOfCircle which, given the radius of a circle, > calculates the area of the circle, > > showAreaOfCircle 12.3 ⇒ "The area of a circle with radius 12.3cm is > about 475.2915525615999 cm^2" > > Use the show function, as well as the predefined value pi :: Floating > a => a to write showAreaOfCircle. > > the type signature works for this function is: showAreaOfCircle :: (Show > a, Floating a) => a -> a -> String > > my question is : 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 > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180404/643206b5/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 4 *****************************************