Hi, enlightenment much appreciated for my newbie question --
to achieve:
append' [ [1, 2], [3, 4], [5] ] 6 - [ [1, 2], [3, 4], [5, 6] ]
append' [ ['1', '2'], ['3'] ] '4' - [ ['1', '2'], ['3', '4'] ]
append' [ [True], [True] ] False - [ [True], [True, False] ]
so I (naively) write:
18) append'
Hi,
JiJie 20) append' x:xs y = [(init x:xs)] ++ [(tail xs)++[y]]
function application (blank) binds stronger than :,
thus you should write
append' (x:xs) y = ...
Cheers
--
Christoph
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
* Ch. A. Herrmann [EMAIL PROTECTED] [020516 21:38]:
Hi,
JiJie 20) append' x:xs y = [(init x:xs)] ++ [(tail xs)++[y]]
function application (blank) binds stronger than :,
thus you should write
append' (x:xs) y = ...
-- so I added the parenthesis:
18) append' :: [[a]] - a -
To make it short:
Main let append' xs y = init xs ++ [last xs ++ [y]]
This works for the three given examples but maybe incorrect
for the task you have in mind, e.g., if xs is empty.
Main append' [ [1, 2], [3, 4], [5] ] 6
[[1,2],[3,4],[5,6]]
Main append' [ ['1', '2'], ['3'] ] '4'
[12,34]
Main