In Python, I can run a bit of code optionally if a given package exists like so:
try:
import asd
# do something with asd
except ImportError:
print "no module asd"
Is there a Haskell equivalent?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not directly, since module imports are resolved at compile-time with GHC. But if you’re using Cabal (and you should be!), you can conditionally depend on a package according to a configuration flag, and then use the
CPPextension to compile code depending on whether or not that dependency is present:This is kind of awkward, though, so I wouldn’t recommend using it unless you really need it…