<div dir="ltr"><div>I am reading Learn you a Haskell for great good and on page 40 - as-patterns.</div><div><br></div><div>I have changed the example slightly to be:</div><div><br></div><div>firstLetter :: String -&gt; String</div>
<div>firstLetter &quot;&quot; = &quot;Empty string, oops&quot;</div><div>firstLetter all@(x:xs) = &quot;The first letter of &quot; ++ all ++ &quot; is &quot; ++ [x] ++ &quot; otherbit &quot; ++ xs</div><div>Then can use like this:</div>
<div><br></div><div>*Main&gt; firstLetter &quot;Qwerty&quot;</div><div>&quot;The first letter of Qwerty is Q otherbit werty&quot;</div><div>But I was confused about the difference between [x] and x and why I have to use [x] in the above example.</div>
<div><br></div><div>For example if I change to</div><div><br></div><div>firstLetter :: String -&gt; String</div><div>firstLetter &quot;&quot; = &quot;Empty string, oops&quot;</div><div>firstLetter all@(x:xs) = &quot;The first letter of &quot; ++ all ++ &quot; is &quot; ++ x ++ &quot; otherbit &quot; ++ xs</div>
<div>I get error:</div><div><br></div><div>Couldn&#39;t match expected type `[Char]&#39; with actual type `Char&#39;</div><div>In the first argument of `(++)&#39;, namely `x&#39;</div><div>In the second argument of `(++)&#39;, namely `x ++ &quot; otherbit &quot; ++ xs&#39;</div>
<div>In the second argument of `(++)&#39;, namely</div><div>  `&quot; is &quot; ++ x ++ &quot; otherbit &quot; ++ xs&#39;</div><div>I can use xs to print &quot;werty&quot; but have to use [x] to print &quot;Q&quot;. Why is that?</div>
<div><br></div><div>What does [x] mean?</div><div><br></div><div>In the (x:xs) : just delimits each element. so x is the first element. Why can I not print by using x?</div><div><br></div><div>Also xs is of what type? list of values? So does this mean x is an element and xs must be of type list? Confused...</div>
<div><br></div></div>