I am struggling to understand a block of code which is extremely easy in imperative world. That's what I need to do: given an executable full path, which is a Maybe FilePath type, I need to execute it conditionally. If the path is a Nothing - print an error, if the path is Just Path - execute it and print message that the file has been executed. Only "Hello, World" can be easier,right? But in Haskell I dug my self into numerous layers of Maybe's and IO's and got stuck. Two concrete questions arise from here: How do I feed a Maybe FilePath into a system or rawSystem? liftM does not work for me here. What is the correct way of doing this kind of conditional branching? Thanks.
Simple pattern matching will do the job nicely.
case command of
Just path -> system path >> putStrLn "Done"
Nothing -> putStrLn "None specified"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With