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: Haskell type definitions (Patrick Mylund Nielsen)
2. Re: </>? Was: doesFileExist cannot get ~/blah_blah right
(Tommy M. McGuire)
3. Re: Conduit composition (Ovidiu D)
4. More than one way to skin a cat question - repeat (Angus Comber)
5. Re: More than one way to skin a cat question - repeat
(Benjamin Edwards)
----------------------------------------------------------------------
Message: 1
Date: Wed, 10 Apr 2013 17:49:50 +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:
<CAEw2jfwwPk2B6s_AYbOtEpN_J3CiAkEKPOJ082shH+aRf=_...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Sorry, that's "implement Num and Ord", not "implement Ord and Eq"!
On Wed, Apr 10, 2013 at 5:39 PM, Patrick Mylund Nielsen <
[email protected]> wrote:
> 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/2f586ab7/attachment-0001.htm>
------------------------------
Message: 2
Date: Wed, 10 Apr 2013 11:21:42 -0500
From: "Tommy M. McGuire" <[email protected]>
Subject: Re: [Haskell-beginners] </>? Was: doesFileExist cannot get
~/blah_blah right
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Neither did I. (And I keep forgetting about hoogle. Sorry.)
Thanks!
On 04/09/2013 08:19 PM, David McBride wrote:
> 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]
> <mailto:[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.
[...]
>
> 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] <mailto:[email protected]>
> http://www.haskell.org/mailman/listinfo/beginners
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Tommy M. McGuire
[email protected]
------------------------------
Message: 3
Date: Wed, 10 Apr 2013 08:52:46 +0300
From: Ovidiu D <[email protected]>
Subject: Re: [Haskell-beginners] Conduit composition
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAKVsE7toz-a2p4LgufyrYmaOxK=ySA=ic-ghmpz1ojdp+vx...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
That makes a lot of sense. Thanks!
On Wed, Apr 10, 2013 at 2:49 AM, Felipe Almeida Lessa <
[email protected]> wrote:
> Complementing David McBride's answer, what misled you is probably the
> precedence of the operators. Your original expression is the same as:
>
> main =
> (((Conduit.sourceList [1..14]
> $= Conduit.map show)
> $= Conduit.iterM putStrLn)
> $= Conduit.iterM putStrLn)
> $$ Conduit.sinkNull
>
> Cheers,
>
> On Tue, Apr 9, 2013 at 7:54 PM, David McBride <[email protected]> wrote:
> > The reason is because the operator $= puts together a source and a
> conduit
> > and returns a new source.
> >
> > The operator =$= is used to combine two conduits into another conduit.
> >
> > With $= if you try to put two conduits together, the underlying types
> just
> > won't match up. They don't match up specifically to tell you that you
> are
> > not quite doing it correctly. It is trying to match the first argument
> to a
> > source, which has its input type restricted to (). Since you have a
> string
> > there, then it complains.
> >
> > So try display = CL.iterM putStrLn =$= CL.iterM putStrLn which does
> exactly
> > what you were looking for.
> >
> >
> > On Tue, Apr 9, 2013 at 6:34 PM, Ovidiu D <[email protected]> wrote:
> >>
> >> Given the following works as expected (i.e. prints the value twice):
> >>
> >> main =
> >> Conduit.sourceList [1..14]
> >> $= Conduit.map show
> >> $= Conduit.iterM putStrLn
> >> $= Conduit.iterM putStrLn
> >> $$ Conduit.sinkNull
> >>
> >> I would expect the following to work as well:
> >> main =
> >> Conduit.sourceList [1..14]
> >> $= Conduit.map show
> >> $= display
> >> $$ Conduit.sinkNull
> >>
> >> display = Conduit.iterM putStrLn $= Conduit.iterM putStrLn
> >>
> >> ...but I get the compilation error:
> >> Couldn't match expected type `String' with actual type `()'
> >> Expected type: Conduit.Conduit String m0 a0
> >> Actual type: Conduit.Source IO ()
> >> In the second argument of `($=)', namely `display'
> >> In the first argument of `($$)', namely
> >> `Conduit.sourceList [1 .. 14] $= Conduit.map show $= display'
> >>
> >> I don't understand why the type of display is inferred to a
> >> Conduit.Source. Can somebody please explain?
> >>
> >> What I want is to have readable names for certain segments in my pipe.
> Is
> >> that possible?
> >>
> >> Thanks,
> >> ovidiu
> >>
> >>
> >> _______________________________________________
> >> Beginners mailing list
> >> [email protected]
> >> http://www.haskell.org/mailman/listinfo/beginners
> >>
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
>
>
>
> --
> Felipe.
>
> _______________________________________________
> 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/6a561beb/attachment-0001.htm>
------------------------------
Message: 4
Date: Thu, 11 Apr 2013 10:43:35 +0100
From: Angus Comber <[email protected]>
Subject: [Haskell-beginners] More than one way to skin a cat question
- repeat
To: Haskell Beginners <[email protected]>
Message-ID:
<CAAtGUhUfsHD=9kf0cup5sa7y_z7xyze2hxbdcpjqvjp415r...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
LYAH beginner on page 55.
What I try to do is see the heading of a section, eg repeat function and
then try to come up with my own version before looking at books
implementation.
Here is my implementation:
repeat' :: a -> [a]
repeat' x = [x] ++ repeat' x
Here is books:
repeat' :: a -> [a]
repeat' x = x:repeat' x
Mine appears to work. Is mine just as good? Are there problems with my
way? Is books way more idiomatic Haskell?
I want to learn the best approaches hence my question.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130411/63ad7d49/attachment-0001.htm>
------------------------------
Message: 5
Date: Thu, 11 Apr 2013 10:47:26 +0100
From: Benjamin Edwards <[email protected]>
Subject: Re: [Haskell-beginners] More than one way to skin a cat
question - repeat
To: haskellbeginners <[email protected]>
Message-ID:
<CAN6k4niCDTUAu_=39gttmpkv-+gpt60qex3p2nnd_gv6g9w...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
(:) is O(1), (++) is O(n). Try and implement (++) and it should be easy to
see why.
On 11 Apr 2013 10:44, "Angus Comber" <[email protected]> wrote:
> LYAH beginner on page 55.
>
> What I try to do is see the heading of a section, eg repeat function and
> then try to come up with my own version before looking at books
> implementation.
>
> Here is my implementation:
>
> repeat' :: a -> [a]
> repeat' x = [x] ++ repeat' x
>
> Here is books:
>
> repeat' :: a -> [a]
> repeat' x = x:repeat' x
>
> Mine appears to work. Is mine just as good? Are there problems with my
> way? Is books way more idiomatic Haskell?
>
> I want to learn the best approaches hence my question.
>
>
> _______________________________________________
> 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/20130411/d74bbf38/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 58, Issue 22
*****************************************