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 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"
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"
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"
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
toMaybewhenMaybe :: (a -> Bool) -> a -> Maybe a
toMaybewhenMaybe predicate x = if predicate x then Just x else Nothing
then your extractCmdOrFail will looks like this
extractCmdOrFail = getArgs >>= check (toMaybewhenMaybe $ {-your predicate-}) "Wrong Number of arguments"
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
toMaybe :: (a -> Bool) -> a -> Maybe a
toMaybe predicate x = if predicate x then Just x else Nothing
then your extractCmdOrFail will looks like this
extractCmdOrFail = getArgs >>= check (toMaybe $ {-your predicate-}) "Wrong Number of arguments"
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"
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
toMaybe :: (a -> Bool) -> a -> Maybe a
toMaybe predicate x = if predicate x then Just x else Nothing
then your extractCmdOrFail will looks like this
extractCmdOrFail = getArgs >>= check (toMaybe $ {-your predicate-}) "Wrong Number of arguments"
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
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
toMaybe :: (a -> Bool) -> a -> Maybe a
toMaybe predicate x = if predicate x then Just x else Nothing
then your extractCmdOrFail will looks like this
extractCmdOrFail = getArgs >>= check (toMaybe $ {-your predicate-}) "Wrong Number of arguments"