title: Haskell error - Couldn't match expected type ‘Char’ with actual type ‘[Char]’
body: <p>I am trying to write a Haskell function which would take a person's full name and return only the last name; for example, <code>getName "Hans Christian Anderson"</code> should return <code>"Anderson"</code>. The function is below:</p>
  
  <pre><code>getname :: String -&gt; String
  getname fullName = do
    let nameList = splitOn " " fullName    -- split the full name into individual names
    let reversedName = reverse nameList    -- reverse the full name
    let lastName = reversedName !! 0       -- get the first name from the reversed list
    return lastName
  </code></pre>
  
  <p>But whenever I try to compile this, I get the following error:</p>
  
  <pre><code>Couldn't match expected type ‘Char’ with actual type ‘[Char]’
  In the first argument of ‘return’, namely ‘lastName’
  In a stmt of a 'do' block: return lastName
  </code></pre>
  
  <p>I'm not sure I fully understand this error. As I understand Haskell (I am quite new to it) the structure <code>[Char]</code> would be the same as <code>String</code>, which is what I'm looking for. I just don't understand why it's expecting this <code>Char</code> type that it seems is appearing in the return statement as a String. I have gone over each line and they seem to be correct to me.</p>
  
  <p>Any advice on why this behavior is occurring and how to fix it is much appreciated.</p>