Talk:Total circles area: Difference between revisions

m (moved Talk:Total Circles Area to Talk:Total circles area: We try to only capitalize the first word in RC titles for consistency.)
Line 78:
 
::: I think it's fine. I changed the polyline area function, maybe it's clearer this way. Also added some comments explaining some odd stuff I did in the code. One thing sort of amuses me is, is there really a need for an <code>Angle</code> type? I mean, it does no harm, but angles are really just plain numbers and doesn't do anything to distinguish itself from a <code>Double</code>. --[[User:Ledrug|Ledrug]] 06:11, 22 September 2012 (UTC)
 
:::: Your question is almost as interesting as the circles area Task itself.
 
:::: Unless you go to extremes, in such situations there is no wrong/correct solutions, just better/worse ones. It's often a judgement call. And judgement sometimes requires having experience in the (Haskell) language.
 
:::: I am learning Haskell so I have tried to see how well it manages subtypes of simple values. The answer is: mixed.
 
:::: It's easy to remove the Angle newtype from this program, if not desired.
 
:::: The program is a little more complex than before, as you see I have had to unpack the angle argument of arcPoint, I have defined a Pi angle, I have had to use a language extension (GeneralizedNewtypeDeriving) to do it simply, and so on.
 
:::: Functional languages like Haskell recognize and show the value of giving different types to different entities. In F# you even add units of measures (http://msdn.microsoft.com/en-us/library/dd233243.aspx ) to variables (many other languages have libraries for it, but I think they are rarely used in small programs like this). The idea of encoding units of measure or the meaning of values like Angle in the type system is to help avoid mistakes like mixing things that must not mix.
 
:::: In this program Angle has not spot bugs, but I think it helps self-document a bit better this sparsely comment code. One advantage of using types over comments is that the (Haskell) compiler enforces their correct usage. As example, the type of the aNorm function is "Angle -> Angle". Now it's easy to understand that "a" in its name refers to angle, and "Norm" of the function name means putting the angle value back in a simple range of values, no comments on this function are required now.
 
:::: In this program there are other unspecified Doubles (beside the input data itself), the return types of arcArea, pathArea, polylineArea and circlesArea. All of them are the same type, of areas of surface. This means that if we use units of measures system like in F# code, such Doubles need to be products of two distances. Currently this is not encoded in the types of this program.
 
:::: If you want and you have some time, I suggest you to add an image (like the ones in the Stack Overflow thread) to the Haskell code to help show how your program works, using only on four or five of the input circles for visual simplicity. --[[User:Bearophile|bearophile]] 11:57, 22 September 2012 (UTC)
 
==Link==