Reputation: 19
I am trying to get true when both a and b are true or both of them are false. Can someone tell me what am I doing wrong?
imply :: (a -> Bool, b -> Bool) -> Bool
a = False
b = True
imply (a, a) = True
imply (b, b) = True
imply _ = False
Upvotes: 1
Views: 279
Reputation: 60463
I'm going to make a guess about what you want, since it seems like you are struggling with the basics of Haskell syntax. Consider going through a tutorial if you are not already.
I agree with @bradrn that the function you are looking for is probably this one:
imply :: (Bool, Bool) -> Bool
imply (True, True) = True
imply (False, False) = True
imply _ = False
I could explain all sorts of things about what you did, but I figured you just needed to see an example of how this looks. I'm happy to answer any questions you have about it in the comments.
To use this function, say, after loading the file in ghci
, you type:
ghci> imply (True, False)
False
ghci> imply (False, False)
True
Note that in Haskell the convention is to define functions curried, so we would instead see
imply :: Bool -> Bool -> Bool
imply True True = True
...
ghci> imply True False
False
But the two versions are (almost) equivalent.
Upvotes: 5