On Wed, Apr 3, 2013 at 5:01 AM, Angus Comber <anguscomber@gmail.com> wrote:
In the (x:xs) : just delimits each element. so x is the first element. Why can I not print by using x?

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...

Actually, you just answered yourself. x is an element, xs is a list. (++) combines lists, so to insert your element using (++) you need to make it a list. [x] is a list containing your element x and nothing else.

Another way to do it is to do the same as the pattern match, but in this case that's kinda ugly:

    firstLetter all@(x:xs) = "The first letter of " ++ all ++ " is " ++ (x : " otherbit ") ++ xs

or

    firstLetter all@(x:xs) = "The first letter of " ++ all ++ " is " ++ (x : []) ++ " otherbit " ++ xs

(note that "is of type list" is incomplete; list of *what*? In this case, list of Char. Haskell String is just [Char] (list of Char), which is highly convenient but a bit slow in real programs that manipulate a lot of String-s.)

--
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net