O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

A quadratic equation is represented by ax^2 + bx + c = 0. There are three possible cases that we have to handle:

Case Condition Root 1 Root 2 Remarks
I a = 0 and b = 0 ERROR ERROR
II a = 0 x = -c/b Not applicable Linear equation
III a and b are non-zero, delta = b2 - 4ac
III-A delta = 0 -b/(2a) -b/(2a) Perfect square
III-B delta > 0 (-b+sqrt(delta))/(2a) (-b-sqrt(delta))/(2a) Real roots
III-C delta < 0 (-b+sqrt(delta))/(2a) (-b-sqrt(delta))/(2a) Complex roots

 

We will define a module at the top of the file with the Quadratic module where the name of the module matches file name, and it starts with a capital letter. The Quadratic module is followed by the definition of module (data types and functions ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required