Skip to main content
Code Review

Return to Revisions

4 of 4
replaced http://stackoverflow.com/ with https://stackoverflow.com/

The code is short and nicely done, so I don't have much comment

In branch, you could use void instead of return ()

branch cmd 'y' = system cmd >> void
branch cmd 'n' = putStrLn "Command Cancelled" >> getChar >> void

In your 'n' match, you use "getChar". I think it's to prevent the console from closing, right? Be aware that there is other ways, but it really depend on how you want to use your program.

Haskell use camelCase, so shutdown_path and rundll32_path should be shutdownPath and rundll32Path

Check

Your actual check functions are fine. But if you have more case like this, you should really consider this:

You could make the check function a top level one like this

check :: String -> Maybe a -> a
check _ (Just s) = s
check errorMsg Nothing = error errorMsg

The check call from findCmdOrFail will remain practically unchanged, you just have to add your error message

The interesting part is the one from extractCmdOrFail, you have to use an helper function that I didn't find on hackage

whenMaybe :: (a -> Bool) -> a -> Maybe a
whenMaybe predicate x = if predicate x then Just x else Nothing

then your extractCmdOrFail will looks like this

extractCmdOrFail = getArgs >>= check (whenMaybe $ {-your predicate-}) "Wrong Number of arguments"
Bruno
  • 592
  • 3
  • 12
default

AltStyle によって変換されたページ (->オリジナル) /