Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Haskell: where clause

Most of the times we need Intermediate results to get the final outcome, By using where Clause we can define intermediate results.


Suppose if a Triangle has sides a, b and c. As per Herons’s formula, following formula is used to calculate area of triangle.
Where s is semi perimeter.
triangle.hs

areaOfTriangle a b c = sqrt (s * (s - a) * (s - b) * (s - c))
where
s = (a + b + c) / 2


*Main> :load triangle.hs
[1 of 1] Compiling Main ( triangle.hs, interpreted )
Ok, modules loaded: Main.
*Main> areaOfTriangle 40 40 20
387.2983346207417


Examples
1. Find sum of squares of two numbers


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Haskell: where clause

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×