title: How to avoid “Exception: Prelude.head: empty list”? - Haskell
body: <p>Good evening everyone, I'm new to haskell. I'm trying to sum up a list of reading a string Unicode values and store them in a list and then sum the integers up. </p>
  
  <pre><code> getLetterUnicodeValue :: Char -&gt; Int
   getLetterUnicodeValue l = (ord l) - 64
  
   unicodeValueList :: String -&gt; [Int]
   unicodeValueList x = getLetterUnicodeValue (head x) : unicodeValueList (tail x)
  
   total :: [Int] -&gt; Int
   total []     = 0
   total x = (head x) + (total (tail x))
  </code></pre>
  
  <p>I got the error of empty list when the string come to the last character and the sum up function cannot successfully execute. Is there any way to stop the function <code>unicodeValueList</code> when it comes to its end.</p>
  
  <pre><code>*** Exception: Prelude.head: empty list
  </code></pre>