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.  Trying to understand function types eg iterate   (a -> a)
      (Angus Comber)
   2. Re:  Trying to understand function types eg iterate (a -> a)
      (Peter Hall)
   3. Re:  Trying to understand function types eg iterate (a -> a)
      (divyanshu ranjan)
   4.  How to get each list in a list of lists for      filter (Angus Comber)
   5. Re:  How to get each list in a list of lists for  filter
      (divyanshu ranjan)


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

Message: 1
Date: Tue, 31 Dec 2013 14:46:03 +0000
From: Angus Comber <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: [Haskell-beginners] Trying to understand function types eg
        iterate (a -> a)
Message-ID:
        <CAAtGUhV_mWHknBSRQ=N_8LUrB1=8ovr39akxk+e1pfsrcr9...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

iterate' :: (a -> a) -> a -> [a]

I am trying going to go ahead and write my own iterate function.  But
before I do I want to be clear on types.

Looking at  :: (a -> a) -> a -> [a]

The first part is (a -> a)  Now because it is in parentheses it is a
function?

I can call iterate like this:
take 5 $ iterate (*2) 5

So (*2) is a possible function.  Does the brackets mean it is a function,
the left hand a is indicating a general type and the right hand a means the
return type must be the same as the function type.  Eg in the case of (*2)
the 2 is an Int so the function returns and Int?  Is my understanding
correct?

How could this be better explained?

The last bit is easier to understand.  a -> [a] meaning a singleton of
general type and [a] means a list of same type.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20131231/2633a939/attachment-0001.html>

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

Message: 2
Date: Tue, 31 Dec 2013 14:53:44 +0000
From: Peter Hall <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Trying to understand function types
        eg iterate (a -> a)
Message-ID:
        <caa6hak5kvgh5kivzeidbop0qjso5iplq0ara2efxfesepvy...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

When you wrap an operator in parentheses and supply just one of its
arguments, then it's called an operator section. It's syntactic sugar for
partially applying the operator, as you can with other functions.

This:
    (*2)

is exactly equivalent to:
    (\x -> x*2)

and it's type is something like:
    Int -> Int

And:
    (2:)

is equivalent to:
    (\x -> 2:x)

etc



On 31 December 2013 14:46, Angus Comber <[email protected]> wrote:

> iterate' :: (a -> a) -> a -> [a]
>
> I am trying going to go ahead and write my own iterate function.  But
> before I do I want to be clear on types.
>
> Looking at  :: (a -> a) -> a -> [a]
>
> The first part is (a -> a)  Now because it is in parentheses it is a
> function?
>
> I can call iterate like this:
> take 5 $ iterate (*2) 5
>
> So (*2) is a possible function.  Does the brackets mean it is a function,
> the left hand a is indicating a general type and the right hand a means the
> return type must be the same as the function type.  Eg in the case of (*2)
> the 2 is an Int so the function returns and Int?  Is my understanding
> correct?
>
> How could this be better explained?
>
> The last bit is easier to understand.  a -> [a] meaning a singleton of
> general type and [a] means a list of same type.
>
>
>
>
>
>
> _______________________________________________
> 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/20131231/33545c3e/attachment-0001.html>

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

Message: 3
Date: Tue, 31 Dec 2013 20:25:13 +0530
From: divyanshu ranjan <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Trying to understand function types
        eg iterate (a -> a)
Message-ID:
        <cal9hw26ahz7gpdm0qebdvg-+-hr9quc2dalnvqbcxjnd1pv...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi Angus,

   Your understanding is correct. Parenthesis is need in a -> a to specify
that it is function from a to a because associativity of -> is from right
to left. (*2) is section, you can read more
   about here :
http://www.haskell.org/haskellwiki/Section_of_an_infix_operator.

   Type of (*2) is (Num a) :: a -> a rather than particular type Int.


Thanks
Divyanshu Ranjan





On Tue, Dec 31, 2013 at 8:16 PM, Angus Comber <[email protected]> wrote:

> iterate' :: (a -> a) -> a -> [a]
>
> I am trying going to go ahead and write my own iterate function.  But
> before I do I want to be clear on types.
>
> Looking at  :: (a -> a) -> a -> [a]
>
> The first part is (a -> a)  Now because it is in parentheses it is a
> function?
>
> I can call iterate like this:
> take 5 $ iterate (*2) 5
>
> So (*2) is a possible function.  Does the brackets mean it is a function,
> the left hand a is indicating a general type and the right hand a means the
> return type must be the same as the function type.  Eg in the case of (*2)
> the 2 is an Int so the function returns and Int?  Is my understanding
> correct?
>
> How could this be better explained?
>
> The last bit is easier to understand.  a -> [a] meaning a singleton of
> general type and [a] means a list of same type.
>
>
>
>
>
>
> _______________________________________________
> 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/20131231/9807d666/attachment-0001.html>

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

Message: 4
Date: Tue, 31 Dec 2013 18:48:59 +0000
From: Angus Comber <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: [Haskell-beginners] How to get each list in a list of lists
        for     filter
Message-ID:
        <CAAtGUhXO=spFyLeZh3V3JQ=h+tqkrh3k2ncdew-mnf91xha...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I am getting a list of lists from chop9.  I want to somehow filter each
element in the list.  How do I do that.

I have encoded binary data eg [1,1,0,0,1,0] etc

Each 9th bit is a parity bit which is checked using this function:

type Bit = Int

paritychecker :: [Bit] -> Bool
paritychecker xs | length xs == 9 && ((sum (init xs)) `mod` 2) == (last xs)
= True
                 | otherwise = False


In the stream (the list) I use chop to retrieve each block of 9 bits as in:

chop9 :: [Bit] -> [[Bit]]
chop9 [] = []
chop9 bits = take 8 bits : chop9 (drop 8 bits)

I have been playing with this sort of thing:
filter paritychecker ??? chop9 [1,0,0,0,1,1,1,0,0,...]

But doesn't work.

I want to end up with all the 9 bit chunks which pass the filter.  So my
end type should be [[Bit]]

paritychecker requires a list - eg [Bit] . So I want to run paritychecker
on each element returned from chop9.  How do I do that?

Example encoded data stream:
[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]

Angus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20131231/e4a637b8/attachment-0001.html>

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

Message: 5
Date: Wed, 1 Jan 2014 00:27:07 +0530
From: divyanshu ranjan <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to get each list in a list of
        lists for       filter
Message-ID:
        <CAL9hw25LhKbZnx2mRu29QBPNk-OjGdpFNKUa0pCBD9_=7gs...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi Angus,
    Try placing $ in place of ???.  Type of filter is (a->Bool) -> [a] ->
[a]. $ is of type (a->b) -> a -> b  but it's low priority so left and right
hand side is calculated before function application.

Thanks
Divyanshu Ranjan


On Wed, Jan 1, 2014 at 12:18 AM, Angus Comber <[email protected]> wrote:

> I am getting a list of lists from chop9.  I want to somehow filter each
> element in the list.  How do I do that.
>
> I have encoded binary data eg [1,1,0,0,1,0] etc
>
> Each 9th bit is a parity bit which is checked using this function:
>
> type Bit = Int
>
> paritychecker :: [Bit] -> Bool
> paritychecker xs | length xs == 9 && ((sum (init xs)) `mod` 2) == (last
> xs) = True
>                  | otherwise = False
>
>
> In the stream (the list) I use chop to retrieve each block of 9 bits as in:
>
> chop9 :: [Bit] -> [[Bit]]
> chop9 [] = []
> chop9 bits = take 8 bits : chop9 (drop 8 bits)
>
> I have been playing with this sort of thing:
> filter paritychecker ??? chop9 [1,0,0,0,1,1,1,0,0,...]
>
>  But doesn't work.
>
> I want to end up with all the 9 bit chunks which pass the filter.  So my
> end type should be [[Bit]]
>
> paritychecker requires a list - eg [Bit] . So I want to run paritychecker
> on each element returned from chop9.  How do I do that?
>
> Example encoded data stream:
>
> [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]
>
> Angus
>
> _______________________________________________
> 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/20140101/9476bfd1/attachment.html>

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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 66, Issue 23
*****************************************

Reply via email to