I am trying to write a simple function that would bind to LDAP server and return a IO Bool value so that I can analyze the return in a conditional statement later.
This little snippet below works and prints an error if bind fails but it is not what I need.
import LDAP.Init
import LDAP.Exceptions
auth :: IO ()
auth = do
c <- ldapOpen "10.1.1.11" 3268
let bnd =ldapSimpleBind c "myusername@domain.local" "mypassword"
catchLDAP bnd (\_ -> error "Wrong user name or password")
I get an error if I try to return anything but IO () by the function that deals with exception. I need it to return IO Bool.
‘ldapSimpleBind’ just throws an exception if unsuccessful and that’s all. Catching exceptions will only allow me to return an IO ()
What I need is to return something meaningful so that I can do something useful with the return value.
I am clearly missing something as the signature of catchLDAP in the docs is :: IO a -> (LDAPException -> IO a) -> IO a
What am I doing wrong?
Thanks.
Your
bndaction doesn’t returntruewhen it succeeds, and the error handler just callserror,So it seems that you could just
let bnd' = bnd >> return true,then,
catchLDAP bnd' $ \_ -> return false.