I want to make a basic Haskell program in which an user can give in the name of a locker, and see if that locker is already used or not. (not for real life use, just an exercise I thought of).

This is my code:

locker :: [(String, Bool)] locker = [ ("A1", True), ("A2", True), ("A3", False), ("B1", True), ("B2", False), ("B3", False), ("C1", True), ("C2", False), ("C3", False) ] isTaken :: (String, Bool) -> Bool isTaken xs = if (snd xs) == True then True else False isTaken' :: String -> Bool isTaken' x y = if fst (locker !! y) == x then do snd $ locker !! y isTaken' x 0 if y > 0 then isTaken' x (y - 1) main = putStrLn $ show $ isTaken' "A1" (length locker) putStrLn $ show $ isTaken $ locker !! 0

The first isTaken function is working. The user just gives in the index of the locker, and it returns if the locker is taken or not.

However, the user has to give in the index; not the name.

At the isTaken' function, I get this error:

haskell_test.hs:29:5: parse error on input `if'

However, I don't see the mistake. Can't I have two if-statements?

I know in Haskell the if function isn't: "If true, do this", but "If true, this is the new value"; yet I don't now how to do this than.

My algorithm in isTaken' is this:

- Keep doing recursive 'loop' until the tuple with given name is found
- If found: Return the second value (True/False => Free/Taken)
- Call the function with y parameter 0, which will break the recursive loop (see second if-statement)

Anyone knows what's wrong? Thanks!