Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Question on (x:xs) form (Christian Maeder)
   2. Re:  Given a list of lists, how to drop the last item in each
      (sub)list. ([email protected])
   3.  Problem specifying fst in tuple from list in     filter
      (Angus Comber)
   4. Re:  Problem specifying fst in tuple from list    in filter
      (David McBride)
   5. Re:  Problem specifying fst in tuple from list in filter
      ([email protected])
   6. Re:  Given a list of lists, how to drop the last item in each
      (sub)list. (Angus Comber)


----------------------------------------------------------------------

Message: 1
Date: Thu, 02 Jan 2014 15:54:36 +0100
From: Christian Maeder <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Question on (x:xs) form
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Am 23.12.2013 15:57, schrieb Angus Comber:
> Why are the brackets required?  And what do they signify?
>
> Eg reverse' x:xs = reverse' xs ++ [x] results in a parse error.

I just want to add that "prefix application"/juxtaposition binds 
stronger than "infix application" and that therefore spaces should be 
put around infix symbols (like ":") to stress this fact:

     reverse x:xs
is the same as
     reverse x : xs
and both are parsed as
     (reverse x) : xs
which is different from
     reverse (x : xs)
although "x:xs" almost looks like "(x:xs)"

Cheers Christian



------------------------------

Message: 2
Date: Thu, 02 Jan 2014 17:31:47 +0200
From: [email protected]
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Given a list of lists, how to drop
        the last item in each (sub)list.
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed; DelSp=Yes

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 <[email protected]>:

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





------------------------------

Message: 3
Date: Thu, 2 Jan 2014 15:52:49 +0000
From: Angus Comber <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: [Haskell-beginners] Problem specifying fst in tuple from list
        in      filter
Message-ID:
        <caatguhvmcdqd8zntt7-8s1-cxvzth5b1putxrzbac_rvh7r...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I can generate a tuple of (index,character) like this:
zip [0..] ['A'..'Z']

To filter on an element in the list I can do:

filter (== (0,'A')) $ zip [0..] ['A'..'Z']
 > [(0,'A')]


But that is very basic, I really want to select on index value (ie first
item in pair). How do I specify the first part of tuple:

filter (fst == 0) $ zip [0..] ['A'..'Z']

this doesn't work.

    Couldn't match expected type `(a1, Char) -> Bool'
                with actual type `Bool'
    In the first argument of `filter', namely `(fst == 0)'
    In the expression: filter (fst == 0)
    In the expression: filter (fst == 0) $ zip [0 .. ] ['A' .. 'Z']
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140102/ea595186/attachment-0001.html>

------------------------------

Message: 4
Date: Thu, 2 Jan 2014 11:04:15 -0500
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Problem specifying fst in tuple from
        list    in filter
Message-ID:
        <can+tr41fdj3tj1howx5ees2zb-8d5rakq9t6y_up25jnkeo...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

You can go:

filter ((==0) . fst)


which is equivalent to

filter (\x -> fst x == 0)

On Thu, Jan 2, 2014 at 10:52 AM, Angus Comber <[email protected]> wrote:
> I can generate a tuple of (index,character) like this:
> zip [0..] ['A'..'Z']
>
> To filter on an element in the list I can do:
>
> filter (== (0,'A')) $ zip [0..] ['A'..'Z']
>  > [(0,'A')]
>
>
> But that is very basic, I really want to select on index value (ie first
> item in pair). How do I specify the first part of tuple:
>
> filter (fst == 0) $ zip [0..] ['A'..'Z']
>
> this doesn't work.
>
>     Couldn't match expected type `(a1, Char) -> Bool'
>                 with actual type `Bool'
>     In the first argument of `filter', namely `(fst == 0)'
>     In the expression: filter (fst == 0)
>     In the expression: filter (fst == 0) $ zip [0 .. ] ['A' .. 'Z']
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>


------------------------------

Message: 5
Date: Thu, 02 Jan 2014 18:06:36 +0200
From: [email protected]
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Problem specifying fst in tuple from
        list in filter
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed; DelSp=Yes

You probably want something like the following:

filter (\(index, char) -> index == 0) $ zip [0..] ['A'..'Z']

Functions can be defined anonymously via a lambda abstraction (e.g.  
\(index, char) -> index == 0).

Stavros Mekesis.


Quoting Angus Comber <[email protected]>:

> I can generate a tuple of (index,character) like this:
> zip [0..] ['A'..'Z']
>
> To filter on an element in the list I can do:
>
> filter (== (0,'A')) $ zip [0..] ['A'..'Z']
>  > [(0,'A')]
>
>
> But that is very basic, I really want to select on index value (ie first
> item in pair). How do I specify the first part of tuple:
>
> filter (fst == 0) $ zip [0..] ['A'..'Z']
>
> this doesn't work.
>
>     Couldn't match expected type `(a1, Char) -> Bool'
>                 with actual type `Bool'
>     In the first argument of `filter', namely `(fst == 0)'
>     In the expression: filter (fst == 0)
>     In the expression: filter (fst == 0) $ zip [0 .. ] ['A' .. 'Z']





------------------------------

Message: 6
Date: Thu, 2 Jan 2014 16:17:10 +0000
From: Angus Comber <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Given a list of lists, how to drop
        the last item in each (sub)list.
Message-ID:
        <CAAtGUhW5u4wUon4bW_O-BKY3OmLWyo5LCSjyWrec=itglcw...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I like that :)


On 2 January 2014 15:31, <[email protected]> wrote:

> 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 <[email protected]>:
>
>  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 ???
>>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140102/1ef8889b/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 67, Issue 4
****************************************

Reply via email to