Jump to content

Haskell Question

- - - - -

  • Please log in to reply
No replies to this topic

#1
cordedconch

cordedconch

    Newbie

  • Members
  • Pip
  • 3 posts
Hi there.

I'm trying to write a simple program in Haskell that can determine someone's body mass index.

Here's what I have written:

type Height = Float
type Weight = Float
type PeopleStats = [(String, Height, Weight)]

bmi :: Height -> Weight -> Float
bmi heightCm weightKg = weightKg/(heightCm)^2

healthy :: Height -> Weight -> Bool
healthy heightCm weightKg
| 25 > index && 18 < index = True
| otherwise = False
where index = bmi heightCm weightKg


So far, the function "healthy" can calculate someone's BMI, and the function "healthyPeople" returns a boolean statement determining if the person's BMI falls within the limits which is considered normal for a healthy person.

I want to write a function called "healthyPeople".

healthyPeople :: PeopleStats -> [String]

This function needs to take a list of PeopleStats and returns a list of names (Strings) of people who are deemed to be "healthy" from the "healthy" function.

For example:

If I input [("Lee", 65, 185), ("Wang", 170, 100), ("Tsu", 160, 120)] I will get a list of the names of the people whose BMI returns true form the boolean function in "healthy".

Please help !!!!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users