title: Haskell: How to read user input to be used in a function inside of a do block?
body: <p>I am attempting to run a simple palindrome program in Haskell but I want to request input from the user to be used in the program.</p>
  
  <p>code:</p>
  
  <pre><code>palindrome :: String -&gt; Bool
  palindrome x = x == reverse x
  main = do
    putStrLn "Brendon Bailey CSCI 4200-DB"
    putStrLn "Enter word to test for Palindrome"
    palindrome &lt;- getLine
    putStrLn "Thanks"
  </code></pre>
  
  <p>The code works but it just displays "thanks". If I exclude the last line of the block I get the "last line of do block must be expression" and if I include the actual palindrome code above the do block I get errors saying I need a "let" statement but incorporating one causes more errors. I am brand new to Haskell (and functional programming in general. I do java, c++, and web langs) I think the explanation here will be simple but after reading input output documentation on haskell I still can't figure out the proper way to accomplish this.</p>
  
  <p>I'm doing it this way because my assignment stipulates that I must show the class info when the program is run. The palindrome part works fine without the do block. I'm just attempting to automatically output my text before testing a palindrome. Also how can I set up a haskell script to just run when loaded? I don't want the user to have to type "main" I want it to just run.</p>
  
  <p>edit: </p>
  
  <pre><code>palindrome :: String -&gt; Bool
  palindrome x = x == reverse x
  main = do
    putStrLn "Brendon Bailey CSCI 4200-DB"
    putStrLn "Enter Word"
    x &lt;- getLine
    palindrome x
    putStrLn "thanks"
  </code></pre>
  
  <p>This also doesn't work. How do I get the users input to use in the palindrome???</p>
  
  <p>If the code:</p>
  
  <pre><code>palindrome :: String -&gt; Bool
  palindrome x = x == reverse x
  </code></pre>
  
  <p>works when "palindrome "etc"" is entered in GHCi then why doesn't my second code version do the same thing???</p>
  
  <p>edit 2: 
  Don't forget to enclose print statements in parentheses or Haskell will think it separate input is a separate argument. Dumb mistake but easy to make.</p>