<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-554648336416801700</id><updated>2012-02-16T00:00:03.662-08:00</updated><category term='code'/><category term='Exam'/><category term='assignment'/><category term='from the book Haskell - The Craft of functional Programming'/><category term='Answers'/><category term='APIIT'/><category term='haskell'/><category term='functional programming'/><category term='prolog'/><title type='text'>Haskell Problems Solved..</title><subtitle type='html'>haskell code.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-1348792361820614291</id><published>2009-06-11T12:33:00.000-07:00</published><updated>2009-06-11T12:34:50.717-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='prolog'/><category scheme='http://www.blogger.com/atom/ns#' term='Answers'/><category scheme='http://www.blogger.com/atom/ns#' term='Exam'/><category scheme='http://www.blogger.com/atom/ns#' term='APIIT'/><title type='text'>APIIT Haskell Prolog Exam, APLC exam, questions and answers</title><content type='html'>&lt;div&gt;&lt;h2&gt;Compare and contrast functional and imperative programming languages ( 10 marks)&lt;br /&gt;&lt;/h2&gt;&lt;br /&gt;&lt;b&gt;Functional&lt;/b&gt; programming works by evaluating &lt;b&gt;expressions&lt;/b&gt;, its &lt;b&gt;stateless&lt;/b&gt; and deals with &lt;b&gt;immutable&lt;/b&gt; &lt;b&gt;data&lt;/b&gt;.  In contrast &lt;b&gt;imperative&lt;/b&gt; works with &lt;b&gt;statements&lt;/b&gt;, which when executed alters its global &lt;b&gt;state&lt;/b&gt;. Functional programming requires the functions to be treated more or less like any other value, that can be passed or returned from a function, this concept is also regarded as functions being &lt;b&gt;first&lt;/b&gt;-&lt;b&gt;class&lt;/b&gt;. Further more this allows functions to be nested in code blocks called &lt;b&gt;closures&lt;/b&gt;, these functions are as easy called or manipulated as any other function. Imperative languages like C/C++ lacks this capability.&lt;br /&gt;&lt;br /&gt;example of an expression&lt;br /&gt;            &lt;i style="font-family: Courier New;"&gt;project x (a,b,c)  =  (a, x,(projectDataColumns x (a,b,c)))&lt;br /&gt;&lt;/i&gt;example of an statement&lt;br /&gt;&lt;i&gt;        &lt;/i&gt;&lt;i&gt;    p += 15;&lt;br /&gt;&lt;/i&gt;example of a closure in haskell&lt;i&gt;           &lt;br /&gt;&lt;/i&gt;           &lt;i&gt;f x = (\y -&gt; x &lt;a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:."&gt;+&lt;/a&gt; y) &lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Imperative languages has no implementation of &lt;b&gt;referential&lt;/b&gt; &lt;b&gt;transparency&lt;/b&gt;, i.e the output of an expression might be different based on the state of execution, resulting in &lt;b&gt;side&lt;/b&gt; &lt;b&gt;effects&lt;/b&gt;. Functional languages has its roots in &lt;b&gt;Lambda&lt;/b&gt; &lt;b&gt;Calculus&lt;/b&gt;, i.e the functions implementations mimic that of mathematical function notations. This ensures that calling a function say 'f'  and passing it the value x once or multiple times will always result in the same answer f(x), eliminating side effects. Functions without side effects make code easy to understand and less prone to error.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Iterations&lt;/b&gt; are handled very differently in functional and imperative languages. Imperative languages use the more traditional approach, which utilizes the use of &lt;b&gt;loops&lt;/b&gt; (for, while, do, etc), whereas in functional languages iteration is carried out via the use of &lt;b&gt;tail&lt;/b&gt; &lt;b&gt;recursions&lt;/b&gt; or &lt;b&gt;list&lt;/b&gt; &lt;b&gt;comprehensions&lt;/b&gt;. To illustrate this principle lets look at a nest for loop.&lt;br /&gt;&lt;br /&gt;Imperative approach&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-left: 40px;"&gt;&lt;i&gt;for($i=1;$i&lt;=12;$i++)&lt;br /&gt;{&lt;br /&gt;    for($j=1;$j&lt;=12;$j++)&lt;br /&gt;    {&lt;br /&gt;         $string .= $i*$j;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/i&gt;&lt;/div&gt;The above code calculates the answer to the multiplication table from 1 to 12. In Haskell this code can be implemented using list comprehensions illustrated below.&lt;br /&gt;&lt;br /&gt;           &lt;i&gt;[x*y|x&lt;-[1..12],y&lt;-[1..12]]&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Functional Programming offers more support to create &lt;b&gt;structured&lt;/b&gt; &lt;b&gt;programming&lt;/b&gt; than imperative languages, which is essential for &lt;b&gt;abstractions&lt;/b&gt; and creating of &lt;b&gt;components&lt;/b&gt;, facilitating code reuse. For example its easy to &lt;b&gt;abstract&lt;/b&gt; &lt;b&gt;out&lt;/b&gt; a recursive bit of code in a &lt;b&gt;high&lt;/b&gt; &lt;b&gt;order&lt;/b&gt; &lt;b&gt;function&lt;/b&gt; which will make the code more &lt;b&gt;declarative&lt;/b&gt; and &lt;b&gt;comprehensive&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Functional programming languages like Haskell has &lt;b&gt;automatic garbage collection&lt;/b&gt;, imperative languages like C/C++ doesn't have this feature. Having manual memory management means the code will be prone to &lt;b&gt;memory leaks&lt;/b&gt;, this pitfall is avoided in functional languages, therefor the program is less likely to crash because of memory leaks.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;5 concepts of functional programming languages (10 marks)&lt;br /&gt;&lt;/h2&gt;&lt;br /&gt;&lt;b&gt;Higher Order Functions&lt;/b&gt;, when functions return other functions or accept other functions as arguments these are called higher order functions. For example, given a function to double an integer.&lt;br /&gt;&lt;i&gt;&lt;br /&gt;        Double::Int-&gt;Int&lt;br /&gt;        Double x = x* 2&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;The prelude function Map. can take this function as a parameter as illustrated below&lt;br /&gt;&lt;br /&gt;&lt;i&gt;        xs = [ 1,3,5,6]&lt;br /&gt;&lt;br /&gt;        doubleList xs = map double xs&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;This applies the double function to each element of the list xs. The function Map takes function Double as a parameter.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Pure Functions, &lt;/b&gt;these functions are functions that have no &lt;b&gt;side effects&lt;/b&gt;, i.e they will only return values not yield other actions.(modify state).&lt;br /&gt;&lt;br /&gt;for example a function a function that changes degree Celsius to degree Fahrenheit is a pure function, and conversion of exchange rate, MYR to USD is an impure function, it depends on a lot of external factors, i.e, the answer can be different time to time.&lt;br /&gt; &lt;b&gt;&lt;br /&gt;Lazy Evaluation, &lt;/b&gt;evaluation takes place only when required. It will only evaluate an argument to a function if that's arguments value is needed to compute the overall result. If the argument is structured, i.e if its a &lt;b&gt;tuple &lt;/b&gt;or a &lt;b&gt;list&lt;/b&gt;, it will only evaluate those parts that are needed.&lt;br /&gt;&lt;br /&gt;an example of lazy evaluation is illustrated below.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;        x = fst ( sqrt(16), sqrt(9)&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;here the only the first part sqrt(16) get evaluated, the other part is ignored.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Currying, &lt;/b&gt;This is transforming a function that takes multiple arguments in such a way that it can be called with a chain of functions each with a single argument. An non-curried function's arguments would probably contain tuples.&lt;br /&gt;&lt;br /&gt;an example of an curried function is illustrated below.&lt;br /&gt;&lt;br /&gt;        &lt;i&gt;Multiply m n = m*n&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;non - curried version of this would look like this.&lt;br /&gt;&lt;i&gt;&lt;br /&gt;        Mutilply (m,n) = m*n&lt;br /&gt;&lt;br /&gt;&lt;/i&gt;The curried version can accept one argument and return a function. this function is a higher order function.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Referential Transparency,  &lt;/b&gt;this means the function always evaluates the same no matter what the context is.  There are no side-effects and it does not depend on the state.&lt;br /&gt;for example the mathematical function sin(x) is transparent, i.e it returns the same value for sin(x) no matter what the context is. however the expression x++; ( x = x+1) is not transparent because it alters the value in variable x.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Explain The term Tuple  in context of functional Programming paradigm, Give 3 examples? (5 marks)&lt;br /&gt;&lt;/h2&gt;&lt;br /&gt;Tuples is a way to storing multiple values in a single value. But it requires you to know exactly how many values are to be stored in the tuple. In functional programming languages tuples are useful when we want to return multiple values from a function, or it a can even be used as a primitive data type.&lt;br /&gt;&lt;br /&gt;example 1: tuples can be used in a function to return cordinates.&lt;br /&gt;&lt;i&gt;&lt;br /&gt;    Cordinates :: Int-&gt;Int-&gt;(Int,Int)&lt;br /&gt;    Cordinates x y = (x,y)&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;example 2: Returning compound result, min and max from 2 Ints&lt;br /&gt;&lt;br /&gt;&lt;i&gt;    minAndMax :: Int -&gt; Int -&gt; (Int, Int)&lt;br /&gt;    minAndMax x y&lt;br /&gt;            | x &gt;= y            =  (y, x)&lt;br /&gt;            | otherwise        =  (x, y)&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;example 3:  Functions over tuples, for pattern matching.&lt;br /&gt;&lt;br /&gt;    &lt;i&gt;addPair :: (Int, Int)-&gt; Int&lt;br /&gt;    addPair (x,y) = x+y&lt;br /&gt;&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;h2&gt;Critically access any 3 Characteristics of procedural Programming Languages and include 2 possible benefits.( 16 marks)&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;Procedural languages are based on  procedures (also known as routines or subroutines),&lt;br /&gt;consisting of a series of computational steps to be carried out. It evaluates the code sequentially ( one way)  and is a combination of variables, loops and functions.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Characteristics.&lt;/h3&gt;&lt;b&gt;Modularity, &lt;/b&gt;Procedural languages allows the code to be modular, a function that is used to perform a certain task can be used over and over again with out repeating the code. Modules ensure separation of concerns, this improves maintainability and future expansion.&lt;br /&gt;&lt;br /&gt;Having the codes in modules makes it really easy to manage, and encourages code reuse, same code can be implemented in multiple projects via libraries.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;Scoping &lt;/b&gt;, in specially large systems, involving a lot of variables being passed around in functions, scoping can be very helpful, in ensures that the variables used in function stays within that function. procedures cant use variable from other procedures or another instance of the same procedure without explicit permission.&lt;br /&gt;&lt;br /&gt;example to illustrate basic scoping in procedural languages.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;//code&lt;br /&gt;&lt;br /&gt;var variable1&lt;br /&gt;&lt;br /&gt;function A{&lt;br /&gt;  &lt;br /&gt;     var variabe2;&lt;br /&gt;    &lt;br /&gt;     function C{}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function B {&lt;br /&gt;  &lt;br /&gt;}&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;In the code illustrated above, variable1 is a global variable accessible to all functions, bu variable2 can only be accessed by function A and C. Similarly function C is not available to function B.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Incremental State&lt;/b&gt;, most procedural languages have incremental state as a function of time, i.e the state alters as the program is executed and as the user interacts with it.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3&gt;Benefits&lt;/h3&gt;&lt;b&gt;&lt;br /&gt;Simplicity &lt;/b&gt;, Procedural languages are simple compared to declarative, they offer a clear and concise solution, specially when considering simple tasks, it doesn't force you to create objects or classes to do a simple task ( as some object oriented languages like java do).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Efficiency&lt;/b&gt;,  procedural languages are more efficiently translated into machine language, and they run more efficiently because the level of abstraction is low, in other programming paradigms like declarative the level of abstraction is very high, its more similar to a natural language which translates less efficiently into machine code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Critically access any 3 characteristics of declarative programming languages ? ( 9 marks)&lt;/h2&gt;&lt;b&gt;&lt;br /&gt;Dynamically typed, &lt;/b&gt;declarative programming languages are dynamically typed, i.e variable types and function types are accessed only at run time, therefore some type checks are left for run time. This can be a good thing and a bad thing depending on ones point of view.&lt;br /&gt;&lt;br /&gt;Bad, because it offers comparatively less documentation, specially if its a large project. This can also help catch errors at compile time.&lt;br /&gt;&lt;br /&gt;Good, because very frequently in a statically typed language to do computations manual type casting is required this brings, and often it makes it prone compiler errors. Dynamically typed languages eliminate this pitfall.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;Minimize side effects&lt;/b&gt;, a declarative language tries to minimize or eliminate side effects completely, it accomplishes it by describing what to do, instead on describing how to go about doing this task, which is what an imperative language would do by implementing a detail description of the algorithm.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;Single Assignment&lt;/b&gt;, in declarative languages variables can only have one value assigned to them and this cannot be altered during program execution. This is called non-destructive assignment. This encourages the use of recursive techniques.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;Program flow, &lt;/b&gt;the flow of the program is not determined by control structures, it is left to the language it self. This minimizes logic errors that may occur if a programmer decided to implement this. This is true for other programming paradigms like imperative languages. Further more order of how execution of code is irrelevant.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Critically assess the current use of prolog lanaugage, identify 5 areas where the prolog language plays an important role. (10 marks)&lt;/h2&gt;&lt;br /&gt;&lt;b&gt;Expert Systems,&lt;/b&gt; prolog is used in expert systems, for example it can be used to study and monitor traffic. and provide intelligent traffic control systems, controlling traffic light times and synchronizations based on statistical data collected overtime. Another example would be a medial expert system.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Natural Language Processing&lt;/b&gt;, Prolog is very suitable to parse and do natural language processing. It is used to create spelling correctors or applications that seek out grammetical errors.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;Robotics&lt;/b&gt;, prolog is used in robotics to write create AI programs.&lt;br /&gt;&lt;br /&gt;Intelligent Systems.&lt;br /&gt;&lt;br /&gt;Knowledge representation and reasoning,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Pattern matching,&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Planning and Search. &lt;/b&gt;i.e. Prolog is good at Symbolic AI&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Function to the exponent of a value. ( 25 marks )&lt;br /&gt;&lt;/h2&gt;&lt;br /&gt;&lt;i&gt;Power :: Float-&gt;Float-&gt;Float                                  // function definition&lt;br /&gt;Power m n                                                                //function declaration, m^n, where n is exponent&lt;br /&gt;        | n == 0             =  1                                        //any integer to the power of 0 is 1&lt;br /&gt;        | m == 0            =  0                                        //0 to the power any integer is 0&lt;br /&gt;        | n &gt; 0               =  m * power m (n-1)              //positive powers&lt;br /&gt;        | otherwise         = (1 /m) * power m(n+1)      //negative powers&lt;br /&gt;&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Finding out weather a number is odd or even  (25 marks)&lt;br /&gt;&lt;/h2&gt;&lt;br /&gt;&lt;i&gt;&lt;br /&gt;oddEven :: Int -&gt; String                                         //function definition&lt;br /&gt;oddEven m                                                             //function declaration, m is the input&lt;br /&gt;    | m == 0                   = "Even"                          // 0 is even&lt;br /&gt;    | (mod m 2) == 0      = "Even"                          // even numbers are divisible by 2&lt;br /&gt;    | otherwise                = "Odd"                            //if its not an even number thats make it odd.&lt;br /&gt;    &lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Using if and else construct a recursive function to compare y = x ^ n, where n &gt; 0 and is out type integer ? ( 10 marks )&lt;br /&gt;&lt;/h2&gt;&lt;i&gt;&lt;br /&gt;toPower :: Float -&gt; Float -&gt; Float&lt;br /&gt;toPower m n = &lt;br /&gt; if (n &gt; 0)&lt;br /&gt;    then&lt;br /&gt;         m * power m (n-1)&lt;br /&gt; else&lt;br /&gt;         1&lt;br /&gt;&lt;br /&gt;&lt;/i&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-1348792361820614291?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/1348792361820614291/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/06/apiit-haskell-prolog-exam-aplc-exam.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/1348792361820614291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/1348792361820614291'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/06/apiit-haskell-prolog-exam-aplc-exam.html' title='APIIT Haskell Prolog Exam, APLC exam, questions and answers'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-7162224084701629856</id><published>2009-06-11T12:28:00.000-07:00</published><updated>2009-06-11T12:29:59.521-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='assignment'/><category scheme='http://www.blogger.com/atom/ns#' term='APIIT'/><title type='text'>APIIT haskell Assignment  in 16 lines of code</title><content type='html'>&lt;span style="font-size:78%;"&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;  1 &lt;/span&gt;&gt;type Table = ( String, [String], [[String]])&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;  2 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&gt;top10 = ("LargestCountries",[ "Rank","Country", "Area"],[ [ "1", "Russia", "17075400"] , [ "2", "Canada", "9976140"] , [ "3", "United States", "9629091"] , [ "4", "China", "9596960"] , [ "5", "Brazil", "8511965"] , [ "6", "Australia", "7686850"] , [ "7", "India", "3287590"] , [ "8", "Argentina", "2776890"] , [ "9", "Kazakhstan", "2717306"] , [ "10", "Sudan", "2505810"]] )&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;  3 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;formatSingleRow [][] = "|"&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;  4 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;formatSingleRow (x:xs) (y:ys) = "| " ++ addSpace y x ++ formatSingleRow xs ys where addSpace a b  |  length b &gt; a  = b     |  otherwise  = addSpace (a-1) b ++ " "&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;  5 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;formatValues [] _ = "\n"&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;  6 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&gt;formatValues ((x:xs)) (y:ys) = formatSingleRow x (y:ys) ++ "\n" ++ formatValues xs (y:ys)&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;  7 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&gt;writeTable (x,y,z) = x ++ "\n\n" ++ formatHeader y ([ a+10|(a)&lt;-(map length y)]) ++ &lt;/span&gt;&lt;/span&gt; &lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;formatValues z ([ a+10|(a)&lt;-(map length y)]) where formatHeader x y = formatSingleRow x y ++ "\n" ++ addLine ((length y)*18) "-" ++ "\n" where addLine a b | length b == a  = b  |otherwise    = b ++ addLine (a - 1) b&lt;br /&gt;--the prgram logic&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;  8 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&gt;printTable = putStr.writeTable&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;  9 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&gt;filterByIndex [] _ = []&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;10 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;filterByIndex (x:xs) y = [[value]|(value,ind)&lt;-(zip x [0..]),ind==y] ++ filterByIndex xs y&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;11 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;addListofLists x [] = x&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;12 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;addListofLists (x:xs) (y:ys) = [[ a |a&lt;-x] ++ [ b |b&lt;-y ]] ++ addListofLists xs ys&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;13 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;filterListofLists [] _ = []&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;14 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;filterListofLists (x:xs) (a,b,c) = addListofLists (filterByIndex c (idx x b)) (filterListofLists xs (a,b,c)) where idx x y = [ind|(value,ind)&lt;-(zip y [0..]),value==x]!!0 --gets index of list&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;15 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;project x (a,b,c)  =  (a, x,(filterListofLists x (a,b,c)))&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color: rgb(255, 255, 255); background-color: rgb(0, 0, 0);"&gt;16 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&gt;&lt;/span&gt;&lt;span style="font-size:78%;"&gt;&lt;span style="font-size:85%;"&gt;select feild condition (a,b,c) = (a,b,((filter (\x -&gt; condition (x!!(idx feild b))))c)) where idx x y = [ind|(value,ind)&lt;-(zip y [0..]),value==x]!!0 -- gets index of list&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-7162224084701629856?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/7162224084701629856/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/06/apiit-haskell-assignment-in-16-lines-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/7162224084701629856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/7162224084701629856'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/06/apiit-haskell-assignment-in-16-lines-of.html' title='APIIT haskell Assignment  in 16 lines of code'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-5575791180223745397</id><published>2009-06-11T12:26:00.000-07:00</published><updated>2009-06-11T12:28:32.796-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='assignment'/><category scheme='http://www.blogger.com/atom/ns#' term='APIIT'/><title type='text'>APIIT haskell Assignment</title><content type='html'>&lt;span style="font-size:78%;"&gt; type Table = ( String, [String], [[String]])&lt;br /&gt;top10:: Table&lt;br /&gt;top10 = ("LargestCountries",[ "Rank","Country", "Area"],[ [ "1", "Russia", "17075400"] , [ "2", "Canada", "9976140"] , [ "3", "United States", "9629091"] , [ "4", "China", "9596960"] , [ "5", "Brazil", "8511965"] , [ "6", "Australia", "7686850"] , [ "7", "India", "3287590"] , [ "8", "Argentina", "2776890"] , [ "9", "Kazakhstan", "2717306"] , [ "10", "Sudan", "2505810"]] )&lt;br /&gt;&lt;br /&gt;--  DYNAMIC FORMATING&lt;br /&gt;&lt;br /&gt;formatSingleRow :: [String] -&gt; [Int] -&gt; String -- formats a single row&lt;br /&gt;formatSingleRow [][] = "|"&lt;br /&gt;formatSingleRow (x:xs) (y:ys) = "| " ++ addSpace y x ++ formatSingleRow xs ys&lt;br /&gt;                    where addSpace a b  |  length b &gt; a  = b     |  otherwise  = addSpace (a-1) b ++ " " --adds white space based on the length of the string in the data feild&lt;br /&gt;&lt;br /&gt;formatValues :: [[String]] -&gt; [Int] -&gt; String --formats records via formatsingrow function&lt;br /&gt;formatValues [] _ = "\n"&lt;br /&gt;formatValues ((x:xs)) (y:ys) = formatSingleRow x (y:ys) ++ "\n" ++ formatValues xs (y:ys)&lt;br /&gt;    &lt;br /&gt;writeTable :: Table -&gt; String -- converts the table to a string&lt;br /&gt;writeTable (x,y,z) = x ++ "\n\n" ++ formatHeader y ([ a+10|(a)&lt;-(map length y)]) ++ formatValues z ([ a+10|(a)&lt;-(map length y)]) --format column names and calls the formatValues function to format data&lt;br /&gt;                    where formatHeader x y = formatSingleRow x y ++ "\n" ++ addLine ((length y)*18) "-" ++ "\n" -- header is formated using formatSingleRows function then a line is added underneath it&lt;br /&gt;                                where addLine a b | length b == a  = b  |otherwise    = b ++ addLine (a - 1) b  -- calulates the length on this line. this can be different depending on how many columns are printed&lt;br /&gt;-- END FORMATING&lt;br /&gt;&lt;br /&gt;printTable::Table-&gt;IO()  -- prints table&lt;br /&gt;printTable = putStr.writeTable&lt;br /&gt;       &lt;br /&gt;--SELECTION OF COLUMNS&lt;br /&gt;&lt;br /&gt;--filters a list of lists (i.e the data portion of the Table to output a single column based on index of the list&lt;br /&gt;--using primitve recursions over lists.&lt;br /&gt;--this function using the zip function to make tupes to identify the index of the list&lt;br /&gt;&lt;br /&gt;filterByIndex::[[String]]-&gt;Int-&gt;[[String]]&lt;br /&gt;filterByIndex [] _ = []&lt;br /&gt;filterByIndex (x:xs) y = [[value]|(value,ind)&lt;-(zip x [0..]),ind==y] ++ filterByIndex xs y&lt;br /&gt;&lt;br /&gt;--adds a lists of lists to another list of lists , i.e adds to columns such as "Rank" and "Country"&lt;br /&gt;--the tradition "++" function will not add it correctly it will just append one list to another&lt;br /&gt;--this function mimics the Zip functions fuctionality but it stead of tupes it returns a list of lists&lt;br /&gt;--with in the list comprehension, an attemp was made first to use "++", wh but it causes winHugs to crash after a few&lt;br /&gt;--adds white space based on the length of the string in the data feild runs, so current method was implemented.&lt;br /&gt;--the cause of this error is not know, possibly a bug in the compliler.&lt;br /&gt;&lt;br /&gt;addListofLists::[[String]]-&gt;[[String]]-&gt;[[String]]&lt;br /&gt;addListofLists x [] = x&lt;br /&gt;addListofLists (x:xs) (y:ys) = [[ a |a&lt;-x] ++ [ b |b&lt;-y ]] ++ addListofLists xs ys&lt;br /&gt;&lt;br /&gt;-- filters list based on given field names  eg ["Rank","Country"], given table name&lt;br /&gt;-- this function can take any number of feilds to filter, it can have dulplicate feilds too.&lt;br /&gt;-- it then filters the data with a help "idx"&lt;br /&gt;-- the purpose of "idx" is to get the index of the columns that need to be filtered&lt;br /&gt;-- this index values will match those of the data fields. which then are selected&lt;br /&gt;-- "idx" using zip function from the prelude library to create tuples for the indexing process&lt;br /&gt;-- multiple columns are achieved with the help of primitive recursion over lists&lt;br /&gt;-- feild names should match that of the table, eg:- if "Rank" was renamed to "id" in table schema&lt;br /&gt;-- then that change should be reflected when calling the function, ["id","Country"]&lt;br /&gt;&lt;br /&gt;projectDataColumns :: [String] -&gt; Table -&gt; [[String]]&lt;br /&gt;projectDataColumns [] _ = []&lt;br /&gt;projectDataColumns (x:xs) (a,b,c) = addListofLists (filterByIndex c (idx x b)) (projectDataColumns xs (a,b,c))&lt;br /&gt;                  where idx x y = [ind|(value,ind)&lt;-(zip y [0..]),value==x]!!0&lt;br /&gt;                   &lt;br /&gt;&lt;br /&gt;-- this is the function that acutally prints outs the columns,&lt;br /&gt;-- function definition would match that of the assignment question&lt;br /&gt;-- it takes in feild names and table name as parameters&lt;br /&gt;-- pattern matching is used to split the table in to a,b,c&lt;br /&gt;-- of which "b" is replaced by the feilds requested byt he user, which is input X&lt;br /&gt;-- "c" is the data portion which is filtered based on X using the previously defined functions&lt;br /&gt;-- to test this function use any of the following lines of code&lt;br /&gt;-- printTable.project["Rank", "Country"]$top10&lt;br /&gt;-- printTable.project["Rank", "Country", "Area"]$top10&lt;br /&gt;-- printTable.project["Rank", "Area", "Country", "Area"]$top10&lt;br /&gt;&lt;br /&gt;project::[String]-&gt;Table-&gt;Table&lt;br /&gt;project x (a,b,c)  =  (a, x,(projectDataColumns x (a,b,c)))&lt;br /&gt;&lt;br /&gt;--SELECTION OF ROWS&lt;br /&gt;&lt;br /&gt;-- this function filters the data rows based on a user defined predicate&lt;br /&gt;-- (String-&gt;Bool) , it uses the "idx" function that was used in the&lt;br /&gt;-- project data columns function&lt;br /&gt;-- it uses the lambda notation to filter rows based on the user given&lt;br /&gt;-- predicate, it can take in any feild name to fitler the data&lt;br /&gt;-- eg, "Rank", "Country", "Area"&lt;br /&gt;-- this fucntion uses a combination of prelude funtions such as zip, filter,!!&lt;br /&gt;-- and pattern matching to accomplish its goal.&lt;br /&gt;-- to test the function the folling code can be tried on winHugs&lt;br /&gt;-- printTable.select "Rank" p $ top10 where p x = read x &lt; (6::Int)&lt;br /&gt;-- filters less than 6 on rank field&lt;br /&gt;-- printTable.select "Rank" p $ top10&lt;br /&gt;--             where p x = ( read x &lt; (6::Int) &amp;amp;&amp;amp; read x &gt; (2::Int) ) &lt;br /&gt;-- filters countires with rank between 2 and 6, not inclusive&lt;br /&gt;-- printTable.select "Rank" p $ top10 where p x = read x == (7::Int)&lt;br /&gt;-- gets country with rank 7&lt;br /&gt;-- printTable.select "Country" p $ top10 where p x = x == "Australia"&lt;br /&gt;-- gets row for Australia&lt;br /&gt;-- printTable.select "Area" p $ top10 where p x = read x &lt; (10000000::Int)&lt;br /&gt;-- gets countries with Area less than 10000000&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;select::String-&gt;(String-&gt;Bool)-&gt;Table-&gt;Table&lt;br /&gt;select feild condition (a,b,c) = (a,b,((filter (\x -&gt; condition (x!!(idx feild b))))c))&lt;br /&gt;                  where idx x y = [ind|(value,ind)&lt;-(zip y [0..]),value==x]!!0&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-5575791180223745397?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/5575791180223745397/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/06/apiit-haskell-assignment.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/5575791180223745397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/5575791180223745397'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/06/apiit-haskell-assignment.html' title='APIIT haskell Assignment'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-4453781852378363882</id><published>2009-02-28T07:19:00.000-08:00</published><updated>2009-02-28T07:20:46.365-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='functional programming'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='from the book Haskell - The Craft of functional Programming'/><title type='text'>Raising a number to the power of another number. exponent. in haskell</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;power :: Float -&gt; Float -&gt; Float&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;power m n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;| n == 0        = 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;| n &gt; 0         = m* power m (n-1)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;| otherwise     = (1 / m)* power m (n+1)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-4453781852378363882?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/4453781852378363882/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/raising-number-to-power-of-another.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/4453781852378363882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/4453781852378363882'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/raising-number-to-power-of-another.html' title='Raising a number to the power of another number. exponent. in haskell'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-3614537641423481776</id><published>2009-02-27T10:16:00.000-08:00</published><updated>2009-02-27T10:25:29.410-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='functional programming'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='from the book Haskell - The Craft of functional Programming'/><title type='text'>finding the highest common factor/divisor for two integers in haskell</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span"  style="color: rgb(255, 0, 0); font-family:'courier new';"&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;hcf :: Int -&gt; Int -&gt; Int&lt;/div&gt;&lt;div&gt;--handles all cases of zero&lt;/div&gt;&lt;div&gt;hcf 0 0 = undefined &lt;/div&gt;&lt;div&gt;hcf m 0 = abs m&lt;/div&gt;&lt;div&gt;hcf 0 n = abs n&lt;/div&gt;&lt;div&gt;hcf m n &lt;/div&gt;&lt;div&gt;    | m == n       = m &lt;/div&gt;&lt;div&gt;    | m &gt; n        = hcf n (rem m n) &lt;div&gt;    | otherwise    = hcf n m&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-3614537641423481776?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/3614537641423481776/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/finding-highest-common-factordivisor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/3614537641423481776'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/3614537641423481776'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/finding-highest-common-factordivisor.html' title='finding the highest common factor/divisor for two integers in haskell'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-4850494108668006069</id><published>2009-02-27T09:42:00.000-08:00</published><updated>2009-02-27T09:43:39.168-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='from the book Haskell - The Craft of functional Programming'/><title type='text'>fibonacci sequence in haskell : not very efficient</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;fib :: Int -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;fib n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| n == 0        = 0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| n == 1        = 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| n &gt; 1         = fib (n - 2) + fib (n - 1)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-4850494108668006069?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/4850494108668006069/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/fibonacci-sequence-in-haskell-not-very.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/4850494108668006069'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/4850494108668006069'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/fibonacci-sequence-in-haskell-not-very.html' title='fibonacci sequence in haskell : not very efficient'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-1045283509079153897</id><published>2009-02-27T09:38:00.000-08:00</published><updated>2009-02-27T09:39:04.405-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='functional programming'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='from the book Haskell - The Craft of functional Programming'/><title type='text'>Integer square root of a positive integer in haskell</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;squareRoot :: Int -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;squareRoot n &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;| n ==  1              = 1 &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;| otherwise            = div (k + ( div n k)) 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;where k = squareRoot(n-1) &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-1045283509079153897?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/1045283509079153897/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/integer-square-root-of-positive-integer.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/1045283509079153897'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/1045283509079153897'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/integer-square-root-of-positive-integer.html' title='Integer square root of a positive integer in haskell'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-7142039512590840117</id><published>2009-02-27T09:35:00.000-08:00</published><updated>2009-02-27T09:36:13.669-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='functional programming'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='from the book Haskell - The Craft of functional Programming'/><title type='text'>Using recursive addition to multiply in haskell</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;multiply :: Int -&gt; Int -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;multiply m n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;| n &gt;= 1        = m + multiply (n-1) m&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;| otherwise     = 0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-7142039512590840117?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/7142039512590840117/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/using-recursive-addition-to-multiply-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/7142039512590840117'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/7142039512590840117'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/using-recursive-addition-to-multiply-in.html' title='Using recursive addition to multiply in haskell'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-3683507820628044040</id><published>2009-02-27T09:33:00.000-08:00</published><updated>2009-02-27T09:35:04.441-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='from the book Haskell - The Craft of functional Programming'/><title type='text'>Finding the factorial in haskell.</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;rangeProduct :: Float -&gt; Float -&gt; Float&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;rangeProduct m n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| m&gt;n             = 0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| m==n            = m&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| otherwise       = m * rangeProduct (m+1) n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;--4.6 Factorial&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;factorial :: Float -&gt; Float&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;factorial n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| n == 0          = 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| otherwise       = rangeProduct 1 n&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-3683507820628044040?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/3683507820628044040/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/finding-factorial-in-haskell.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/3683507820628044040'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/3683507820628044040'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/finding-factorial-in-haskell.html' title='Finding the factorial in haskell.'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-7424786545793500419</id><published>2009-02-27T08:57:00.000-08:00</published><updated>2009-02-27T08:59:36.107-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='from the book Haskell - The Craft of functional Programming'/><title type='text'>finding out how many are equal amongst three numnbers in haskell</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;howManyEqual :: Int -&gt; Int -&gt; Int -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;howManyEqual x y z &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;|((equal x y) + (equal y z) + (equal x z)) == 1     = 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;| otherwise                                         = (equal x y) + (equal y z) + (equal x z)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;equal :: Int -&gt; Int -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;equal x y &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;| x == y           = 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;| otherwise        = 0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-7424786545793500419?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/7424786545793500419/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/finding-out-how-many-are-equal-amongst.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/7424786545793500419'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/7424786545793500419'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/finding-out-how-many-are-equal-amongst.html' title='finding out how many are equal amongst three numnbers in haskell'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-6197789596138543972</id><published>2009-02-27T08:56:00.000-08:00</published><updated>2009-02-27T08:57:25.108-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='from the book Haskell - The Craft of functional Programming'/><title type='text'>Finding max of two, three or four in haskell</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;maxTwo :: Int -&gt; Int -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;maxTwo x y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;| x&gt;y                   = x&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;| otherwise             = y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;maxThree :: Int -&gt; Int -&gt; Int -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;maxThree x y z &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;|maxTwo x y &gt; z            = maxTwo x y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;|otherwise&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;   = z&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;maxFour :: Int -&gt; Int -&gt; Int -&gt; Int -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;maxFour v x y z&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;| maxThree v x y &gt; z      = maxThree v x y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;| otherwise               = z&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-6197789596138543972?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/6197789596138543972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/finding-max-of-two-three-or-four-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/6197789596138543972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/6197789596138543972'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/finding-max-of-two-three-or-four-in.html' title='Finding max of two, three or four in haskell'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-2956782958189649343</id><published>2009-02-27T08:52:00.000-08:00</published><updated>2009-02-27T08:55:18.007-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='from the book Haskell - The Craft of functional Programming'/><title type='text'>Finding the number of roots in a quadratic equation in haskell</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;rootFunction :: Float -&gt; Float -&gt; Float -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;rootFunction a b c&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| a == 0        = dRoots a b c&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| otherwise     = numberNDroots a b c&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;numberNDroots :: Float -&gt; Float -&gt; Float -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;numberNDroots a b c &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| b^2 &gt; (4.0*a*c)      = 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| b^2 == (4.0*a*c)     = 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| b^2 &lt; (4.0*a*c)      = 0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;dRoots :: Float -&gt; Float -&gt; Float -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;dRoots a b c &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| b /= 0               = 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| b == 0 &amp;amp;&amp;amp; c /= 0     = 0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="font-family:'courier new';"&gt;&lt;span class="Apple-style-span"  style="font-size:small;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;| b == 0 &amp;amp;&amp;amp; c == 0     = 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-2956782958189649343?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/2956782958189649343/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/finding-number-of-roots-in-quadratic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/2956782958189649343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/2956782958189649343'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/finding-number-of-roots-in-quadratic.html' title='Finding the number of roots in a quadratic equation in haskell'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-554648336416801700.post-2801670731591000425</id><published>2009-02-27T08:46:00.000-08:00</published><updated>2009-02-27T08:48:28.666-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='functional programming'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='code'/><title type='text'>Finding the average of three numbers in haskell</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;averageThree :: Float -&gt; Float -&gt; Float -&gt; Float&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;averageThree  a b c = (a + (b + c))/3.0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;isAbove :: Float -&gt; Float -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;isAbove a avg&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; | a &gt; avg = 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt; | otherwise = 0&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;numAbove :: Float -&gt; Float -&gt; Float -&gt; Int&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;numAbove a b c = (isAbove a avg) + (isAbove b avg) + (isAbove c avg)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;  where&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'courier new';"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0);"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;   avg = averageThree a b c&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0); font-family: 'courier new'; font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 0, 0); font-family: 'courier new'; font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/554648336416801700-2801670731591000425?l=haskellsolutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://haskellsolutions.blogspot.com/feeds/2801670731591000425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/finding-average-of-three-numbers-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/2801670731591000425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/554648336416801700/posts/default/2801670731591000425'/><link rel='alternate' type='text/html' href='http://haskellsolutions.blogspot.com/2009/02/finding-average-of-three-numbers-in.html' title='Finding the average of three numbers in haskell'/><author><name>Jinah Adam</name><uri>http://www.blogger.com/profile/01071229033911353647</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
