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:  </>? Was: doesFileExist cannot get ~/blah_blah right
      (David McBride)
   2.  Haskell type definitions (Angus Comber)
   3. Re:  Haskell type definitions (Christopher Young)
   4. Re:  Haskell type definitions (Patrick Mylund Nielsen)
   5. Re:  Problems with parsing in attoparsec (Michel Kuhlmann)


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

Message: 1
Date: Tue, 9 Apr 2013 21:19:56 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] </>? Was: doesFileExist cannot get
        ~/blah_blah right
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAN+Tr43OAHUtH20Aj586QFnF=asnbcufthojyvyc+1tjfyx...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I didn't even know the standard library had a </> operator.  Here's to
learning new things.


On Tue, Apr 9, 2013 at 8:06 PM, Brent Yorgey <[email protected]> wrote:

> On Tue, Apr 09, 2013 at 12:25:10PM -0400, David McBride wrote:
> > There is a package system-filepath
> > http://hackage.haskell.org/package/system-filepath which fixes a lot of
> > quibbles people have with the way filepaths are implemented in haskell.
> > There are apparently a lot of problems with using strings as filepaths,
> > like the fact that they are slow, that they have encoding issues, and
> that
> > people cannot make a path that is system agnostic.
> >
> > So the </> operator in that library just joins two filepaths together
> with
> > the correct slash.
>
> This is all true, though using system-filepath is still annoying to
> use because it doesn't play well with everything else in the Haskell
> ecosystem.  However, I was not referring to the (</>) in
> system-filepath but rather the one in the standard 'filepath' package.
>
> -Brent
>
> _______________________________________________
> 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/20130409/6df99153/attachment.html>

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

Message: 2
Date: Wed, 10 Apr 2013 10:32:41 +0100
From: Angus Comber <[email protected]>
Subject: [Haskell-beginners] Haskell type definitions
To: Haskell Beginners <[email protected]>
Message-ID:
        <CAAtGUhVTS5ukHf1qJhYyXc_M=o9yetehedx_5619cod7_ar...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I am learning Haskell using Learn You a Haskell.  On page 54 is an
implementation of take like so:

    take' :: (Num i, Ord i) => i -> [a] -> [a]
    take' n _
        | n <= 0 = []
    take' _ []   = []
    take' n (x:xs) = x : take' (n-1) xs

I understand all the code apart from the first line.

The :: part I understand as meaning this is a type definition?

(Num i, Ord i) is a tuple.  The first element of the tuple has to be
numeric, fair enough.  the second param has to be able to be ordered.
The parameter is the same - both are i.  This means that the types
have to be the same?

Why is it not (Num i, Ord j)?  Isn't the 2nd tuple element
referring to the list?  Which could be of any type?

What does => signify?

i -> [a] -> [a] means first parameter is numeric?  2nd param is any
type list, 3rd param is any type list.  So this is saying first param
numeric, 2nd param a list of any type and it returns a list of any
type.  Well that is understandable I suppose.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130410/04354568/attachment.htm>

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

Message: 3
Date: Wed, 10 Apr 2013 11:38:41 -0400
From: Christopher Young <[email protected]>
Subject: Re: [Haskell-beginners] Haskell type definitions
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAAtbczraosgtOwA0UJaUukfQ=xxhujpdolxti4ew7pz4fnx...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

This line

take' :: (Num i, Ord i) => i -> [a] -> [a]

just means that take' is a function takes an i and a list of a's and
returns a list of a's. The

(Num i, Ord i) =>

bit just gives you a constraint on what i can be: it must implement both
the Num and the Ord typeclasses. If you call take' with a string and a list
it will fail, e.g., since strings don't implement those typeclasses.

I'm just starting out too, so please correct me if I'm wrong, people.

Best,
Chris


On Wed, Apr 10, 2013 at 5:32 AM, Angus Comber <[email protected]> wrote:

> I am learning Haskell using Learn You a Haskell.  On page 54 is an
> implementation of take like so:
>
>     take' :: (Num i, Ord i) => i -> [a] -> [a]
>     take' n _
>         | n <= 0 = []
>     take' _ []   = []
>     take' n (x:xs) = x : take' (n-1) xs
>
> I understand all the code apart from the first line.
>
> The :: part I understand as meaning this is a type definition?
>
> (Num i, Ord i) is a tuple.  The first element of the tuple has to be
> numeric, fair enough.  the second param has to be able to be ordered.
> The parameter is the same - both are i.  This means that the types
> have to be the same?
>
> Why is it not (Num i, Ord j)?  Isn't the 2nd tuple element
> referring to the list?  Which could be of any type?
>
> What does => signify?
>
> i -> [a] -> [a] means first parameter is numeric?  2nd param is any
> type list, 3rd param is any type list.  So this is saying first param
> numeric, 2nd param a list of any type and it returns a list of any
> type.  Well that is understandable I suppose.
>
> _______________________________________________
> 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/20130410/1e119361/attachment-0001.htm>

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

Message: 4
Date: Wed, 10 Apr 2013 17:39:40 +0200
From: Patrick Mylund Nielsen <[email protected]>
Subject: Re: [Haskell-beginners] Haskell type definitions
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <caew2jfz2bwrkoktkd32bo_hq4o1za1g69-azz2ceh6fm-qj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Yes, it is a type signature. It's "function name :: optional type
constraints => function of type a -> function of type b -> type c"

take' :: Num i => i -> [a] -> [a]     = take' is a function whose first
argument is of type i, where the i type must be an instance of the Num
typeclass. The function also takes a list of values of type a (any specific
type), and returns a list of values of the same type.

take' :: (Num i, Ord i) => i -> [a] -> [a]     = take' is a function whose
first argument is of type i, where the i type must be an instance of both
the Num and Ord typeclasses. The function also takes a list of values of
type a (any one type), and returns a list of values of the same type.

So the tuple behind the => doesn't mean that one of the arguments is a
tuple, or that the constraints apply to the arguments positionally, but
rather that the specified type, e.g. i, must satisfy some constraints--in
this case implement Ord and Eq so that you can check if it's below 0 (Ord)
and use it as a number (Num.) take' :: i -> [a] -> [a] would have been
valid too, but you wouldn't know if you can compare against i, or use it as
a number.

If you wanted to sort the [a], then indeed, you would need to make it take'
:: (Num i, Ord i, Ord a), since sort from Data.List has a type signature of
sort :: Ord a => [a] -> [a]


On Wed, Apr 10, 2013 at 11:32 AM, Angus Comber <[email protected]>wrote:

> I am learning Haskell using Learn You a Haskell.  On page 54 is an
> implementation of take like so:
>
>     take' :: (Num i, Ord i) => i -> [a] -> [a]
>     take' n _
>         | n <= 0 = []
>     take' _ []   = []
>     take' n (x:xs) = x : take' (n-1) xs
>
> I understand all the code apart from the first line.
>
> The :: part I understand as meaning this is a type definition?
>
> (Num i, Ord i) is a tuple.  The first element of the tuple has to be
> numeric, fair enough.  the second param has to be able to be ordered.
> The parameter is the same - both are i.  This means that the types
> have to be the same?
>
> Why is it not (Num i, Ord j)?  Isn't the 2nd tuple element
> referring to the list?  Which could be of any type?
>
> What does => signify?
>
> i -> [a] -> [a] means first parameter is numeric?  2nd param is any
> type list, 3rd param is any type list.  So this is saying first param
> numeric, 2nd param a list of any type and it returns a list of any
> type.  Well that is understandable I suppose.
>
> _______________________________________________
> 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/20130410/f803b2d6/attachment-0001.htm>

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

Message: 5
Date: Wed, 10 Apr 2013 15:59:58 +0200
From: Michel Kuhlmann <[email protected]>
Subject: Re: [Haskell-beginners] Problems with parsing in attoparsec
To: mukesh tiwari <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Hi Mukesh,
thanks for the hint. 
I will try to combine `take 6` with `number`, to avoid `read . T.unpack`. 
I post, if that succeeds.
Greetings, Michel



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

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


End of Beginners Digest, Vol 58, Issue 21
*****************************************

Reply via email to