
Hello folks, just a quickie here and would appreciate any help... In this expression: instance OBSERVATIONS Drinkability WaterWell Volunteer where observe (Drinkability waterWell) volunteer = volunteer {vReport = if (odorQuale (perceive (Odor waterWell) volunteer) == True && clarityQuale (perceive (Clarity waterWell) volunteer) == True && fullnessQuale (perceive (Fullness waterWell) volunteer) == True) then (if (honesty) then "drinkable" else "undrinkable") else (if (honesty) then "undrinkable" else "drinkable")} I get the following error: Couldn't match expected type `Bool' against inferred type `Volunteer -> Bool' In the expression: honesty In the expression: (if honesty then "drinkable" else "undrinkable") In the `vReport' field of a record It is worth mention that Volunteer id defined as follows: data Volunteer = Volunteer {vid:: Id, vloc:: Id, odorQuale:: Bool, clarityQuale:: Bool, fullnessQuale:: Bool, vQuale:: Bool, vReputation:: Float, honesty:: Bool, vReport:: Report} deriving Show Where Report is defined as: type Report = String I understand that the vReport field is not receiving a String as it should, but I have completely failed in knowing why! I just think the nesting of the if statements is correct but wonder why is it not working. What is the correct code to do what I intend from the abofe nonfunctioning if statements? cheers, m

honesty is a field label, so effectively it creates a function honesty :: Volunteer -> Bool This should fix it: if (honesty volunteer) then "drinkable" else "undrinkable"

On Oct 19, 2010, at 16:13, Mohamed wrote:
Hello folks,
just a quickie here and would appreciate any help...
In this expression:
instance OBSERVATIONS Drinkability WaterWell Volunteer where observe (Drinkability waterWell) volunteer = volunteer {vReport = if (odorQuale (perceive (Odor waterWell) volunteer) == True && clarityQuale (perceive (Clarity waterWell) volunteer) == True && fullnessQuale (perceive (Fullness waterWell) volunteer) == True) then (if (honesty) then "drinkable" else "undrinkable") else (if (honesty) then "undrinkable" else "drinkable")}
I suppose this could also be written instance OBSERVATIONS Drinkability WaterWell Volunteer where observe (Drinkability waterWell) volunteer = volunteer { vReport = drinkability } where drinkability = undrinkableIf $ honesty volunteer `xor` odorQuale (perceive (Odor waterWell) volunteer) && clarityQuale (perceive (Clarity waterWell) volunteer) && fullnessQuale (perceive (Fullness waterWell) volunteer) undrinkableIf True = "undrinkable" undrinkableIf False = "drinkable" xor False = id xor True = not infixr 2 xor if I didn't make a mistake. It's maybe a little bit more readable. Btw. How would I rewrite this in applicative style? I came up with something like drinkability = undrinkableIf $ xor . honesty <*> ( (&&) . odorQuale . (perceive $ Odor waterWell) <*> (&&) . clarityQuale . (perceive $ Clarity waterWell) <*> fullnessQuale . (perceive $ Fullness waterWell) ) $ volunteer (not sure it would still compile). However, seems not that readable anymore. Is it not recommended to use applicative style with binary infix operators? Or is there a way to make them readable again? Regards, Bastian

On Oct 19, 2010, at 22:10, Isaac Dupree wrote:
On 10/19/10 14:35, Bastian Erdnüß wrote:
xor False = id xor True = not infixr 2 xor
Also, exclusive-or on Bool can be written as /= (the first boolean is not equal to the second boolean), which makes sense to use because /= is a standard function.
Cool. Never thought of it that way. Then it turns out to be even more easy: instance OBSERVATIONS Drinkability WaterWell Volunteer where observe (Drinkability waterWell) volunteer = volunteer { vReport = drinkability } where drinkability = drinkableIf $ claimedAppereance == honesty volunteer claimedAppereance = odorQuale (perceive (Odor waterWell) volunteer) && clarityQuale (perceive (Clarity waterWell) volunteer) && fullnessQuale (perceive (Fullness waterWell) volunteer) drinkableIf True = "drinkable" drinkableIf False = "undrinkable" Regards, Bastian
participants (4)
-
Bastian Erdnüß
-
Isaac Dupree
-
Mohamed
-
Stephen Tetley