Haskell program to turn off computer This a program I wrote to execute various power-related function on my computer. It accepts one command-line argument that describes what action to take and then performs that action. Usage looks like this:

C:\Users\Noah\My Code\GHCI&gt; power sleep
execute sleep? (y/n)
y

//computer goes to sleep


Here's the code. Any feedback whatsoever is appreciated, regarding either my program's design or the style, formatting and good/bad practices of my code.

--power.hs

import System.Cmd(system)
import System.Environment(getArgs)

type Arg = String --A command-line argument
type Cmd = String --A command to execute

--paths to programs that will carry out the actions
shutdown_path = "C:\\Windows\\System32\\shutdown.exe"
rundll32_path = "C:\\Windows\\System32\\rundll32.exe"

--assoc list mapping arguments to the action that should be taken when that argument is received
cmds :: [(Arg, Cmd)]
cmds = [ ("shutdown",  shutdown_path ++ " /s /t 0"                           ),
         ("sleep",     rundll32_path ++ " powrprof.dll,SetSuspendState 0,1,0"),
         ("hibernate", shutdown_path ++ " /h"                                ), -- does not work
         ("lock",      rundll32_path ++ " user32.dll,LockWorkStation"        ),
         ("restart",   shutdown_path ++ " -t 0 -r -f"                        ) ]

--gets the argument passed to the program. Calls error if there is not exactly one argument.
extractCmdOrFail :: IO Arg
extractCmdOrFail = getArgs &gt;&gt;= check
    where check [s] = return s
          check _   = error "Wrong Number of arguments"

--finds the command to execute from the given command-line arg. Calls error if no command is found.
findCmdOrFail :: Arg -&gt; Cmd
findCmdOrFail s = check $ lookup s cmds
    where check (Just s') = s'
          check Nothing   = error "Unknown command: " ++ s

--prompts the user to confirm whether or not they want to execute the command.
prompt :: Cmd -&gt; Arg -&gt; IO ()
prompt cmd name = putStr ("Execute " ++ name ++ "? (y/n)\n") &gt;&gt; getChar &gt;&gt;= branch cmd

--conditional "loop" that either executes the command, cancels, or awaits valid input.
branch :: Cmd -&gt; Char -&gt; IO ()
branch cmd 'y' = system cmd &gt;&gt; return ()
branch cmd 'n' = putStrLn "Command Cancelled" &gt;&gt; getChar &gt;&gt; return ()
branch cmd _   = getChar &gt;&gt;= branch cmd

--main function
main = extractCmdOrFail &gt;&gt;= (\arg -&gt; prompt (findCmdOrFail arg) arg)
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 &gt;&gt; void
branch cmd 'n' = putStrLn "Command Cancelled" &gt;&gt; getChar &gt;&gt; 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 -&gt; Maybe a -&gt; 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 -&gt; Bool) -&gt; a -&gt; Maybe a
whenMaybe predicate x = if predicate x then Just x else Nothing


then your extractCmdOrFail will looks like this

extractCmdOrFail = getArgs &gt;&gt;= check (whenMaybe  $ {-your predicate-}) "Wrong Number of arguments"