This is a program which uses wreq to either request information from a school utility called Ion or sign up for new activities. I feel the error handling is poor and that I've overused the IO Monad. Most of the methods in Lib.hs are impure and I feel this is poor style. Repo. I'd appreciate any feedback on anything from style to overall design. I also know that I'm using partial functions (mostly head) in Lib.hs which don't always take empty lists and that can lead to exceptions with poor error output and no information for the user and that I need to change that soon.

error-handling example from Main.hs

    configPath <- case configFile options of
        Nothing -> getXdgDirectory XdgConfig "isotope/config"
        Just a  -> return $ fromString a

    configExists <- doesFileExist configPath

    unless configExists (throw NoConfigException)

I also feel that the usage of !! here seems hard-coded and that the return type of string seems like a bad choice but I'm not sure what else to do. Should I have put the output formatting in main?

signup :: Credentials -> BlockInput -> String -> IO String
signup cred blockType activity = do
    blocks <- fetchBlocks cred
    let block = case blockType of
            A -> head blocks
            B -> blocks !! 1
    activities <- fetchBlockActivities cred block
    let found = findActivityFuzzy activities activity
    _ <- postWith opts signupUrl ["block" := block_id block, "activity" := aid found]
    return $ "Signed up for " ++ name found
    where opts = defaults & auth ?~ basicAuth (cred_un cred) (cred_pass cred)

closed as off-topic by Zeta, yuri, Toby Speight, Mast, pacmaninbw Jun 7 at 12:16

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Authorship of code: Since Code Review is a community where programmers improve their skills through peer review, we require that the code be posted by an author or maintainer of the code, that the code be embedded directly, and that the poster know why the code is written the way it is." – Zeta, yuri, Toby Speight, pacmaninbw
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    \$\begingroup\$ Welcome to Code Review! Unfortunately your question is off-topic as of now, as the code to be reviewed must be present in the question. Code behind links is considered non-reviewable. Please add the code you want reviewed in your question. Thanks! \$\endgroup\$ – Toby Speight Jun 7 at 7:24

Browse other questions tagged or ask your own question.