[Haskell-beginners] Given a list of lists, how to drop the last item in each (sub)list.

smekesis at csd.auth.gr smekesis at csd.auth.gr
Thu Jan 2 15:31:47 UTC 2014


Hi Angus! Take a look at the following function:

discardParityByte :: [[Integer]] -> [[Integer]]
discardParityByte = map init

It returns a list constructed by applying "init" to all items in the  
list you pass in. "init" accepts a list and returns the list without  
its last item.

Stavros Mekesis.


Quoting Angus Comber <anguscomber at gmail.com>:

> I have a list like this:
>
> [[1,0,0,0,1,1,1,0,0],[1,1,1,0,1,1,1,0,0],[1,0,1,0,0,1,1,0,0],[0,1,0,0,1,1,1,0,0],[0,0,1,0,1,1,1,0,0],[1,0,0,1,1,1,1,0,1]]
>
> The 'inner' list is a list of 9 items.  I want to process the list so that
> a list of lists is returned but the 9th element in each inner list is
> dropped.
>
> So the function type would be [[a]] -> [[a]]
>
> So to get started I wrote a function like this:
>
> discardparitybyte :: [[Bit]] -> [[Bit]]
>
> But then not sure how to transform the inner list.
>
> I know I can access the first inner element using take 1 list.  But how do
> I then access/manipulate this inner list?
>
> discardparitybyte (x:xs) = take 9 ??? (take 1 xs) : discardparitybyte ???





More information about the Beginners mailing list