Yes it seems that ++ concatenates lists not elements and that was the
underlying problem.

I have subscribed to the beginners list - didn't know there was one for
people like me just starting to walk :)


On 3 April 2013 14:39, Brandon Allbery <allber...@gmail.com> wrote:

> On Wed, Apr 3, 2013 at 5:01 AM, Angus Comber <anguscom...@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
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
_______________________________________________
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to