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: Quickcheck2 - writing a modifier for test data
(Nathan H?sken)
2. Re: [IO String] to IO [String] (Brent Yorgey)
3. Re: [IO String] to IO [String] (Ovidiu D)
4. Re: [IO String] to IO [String] (Kim-Ee Yeoh)
5. Re: [IO String] to IO [String] (Lyndon Maydwell)
6. finding the cause of an error (here head: empty list)
(Nathan H?sken)
----------------------------------------------------------------------
Message: 1
Date: Sun, 31 Mar 2013 13:13:18 +0200
From: Nathan H?sken <[email protected]>
Subject: Re: [Haskell-beginners] Quickcheck2 - writing a modifier for
test data
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
That was it.
Thanks!
On 03/31/2013 12:30 PM, Brent Yorgey wrote:
> On Sun, Mar 31, 2013 at 12:21:48PM +0200, Nathan H?sken wrote:
>>
>> No instance for (QuickCheck-2.4.2:Test.QuickCheck.Arbitrary.Arbitrary
>> ValidPos)
>
> The fact that it actually lists the package and version number in the
> error message strongly suggests that the problem is conflicting
> versions of the QuickCheck package. Do 'ghc-pkg list QuickCheck' to
> see if you have multiple versions installed, and unregister all but
> one of them.
>
> -Brent
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 2
Date: Sun, 31 Mar 2013 07:30:08 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] [IO String] to IO [String]
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
To elaborate a bit: you originally said "I don't like that the line
processing I'm doing will have to be in the IO monad" -- but since you
want the processing of the list of Strings to be interleaved with IO
operations, you have no choice. Pure functions of type [String] ->
[String] cannot have their evaluation interleaved with IO operations.
Note that functions using lazy I/O such as getContents, readFile,
etc. can create exceptions to this -- but these use unsafeInterleaveIO
under the hood and are widely regarded as problematic. So you could
try using unsafeInterleaveIO, but it is unsafe for a reason. I do not
actually know what is required to ensure you are using it safely;
perhaps someone else could elaborate on this.
-Brent
On Sun, Mar 31, 2013 at 01:48:23PM +0300, Ovidiu D wrote:
> Right. I definitely want the lazy behavior.
>
> Thanks
>
>
> On Sun, Mar 31, 2013 at 1:29 PM, Brent Yorgey <[email protected]>wrote:
>
> > Unfortunately, with the definition
> >
> > f = getLine : f
> >
> > this will not work. 'sequence f' has to do *ALL* the IO before you
> > can process even the first String in the resulting list. Since it is
> > infinite, it will just sit there reading lines forever but never
> > letting you process them.
> >
> > I think in this case using [IO String] is actually a good solution.
> >
> > -Brent
> >
> > On Sun, Mar 31, 2013 at 12:24:33PM +0200, Nathan H?sken wrote:
> > > Try
> > >
> > > sequence :: Monad m => [m a] -> m [a]
> > >
> > > I thinkg
> > >
> > > sequence f :: IO [String]
> > >
> > > should be what you want.
> > >
> > > On 03/31/2013 12:19 PM, Ovidiu D wrote:
> > > >I have the function f which reads lines form the stdin and looks like
> > this:
> > > >
> > > >f :: [IO String]
> > > >f = getLine : f
> > > >
> > > >What I don't like is the fact that the line processing I'm doing will
> > > >have to be in the IO Monad
> > > >
> > > >I would like to make this function to have the signature
> > > >f : IO [String]
> > > >...such that I can get rid of the IO monad and pass the pure string list
> > > >to the processing function.
> > > >
> > > >Can I do this?
> > > >
> > > >Thanks
> > > >
> > > >
> > > >_______________________________________________
> > > >Beginners mailing list
> > > >[email protected]
> > > >http://www.haskell.org/mailman/listinfo/beginners
> > > >
> > >
> > >
> > > _______________________________________________
> > > Beginners mailing list
> > > [email protected]
> > > http://www.haskell.org/mailman/listinfo/beginners
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 3
Date: Sun, 31 Mar 2013 14:42:40 +0300
From: Ovidiu D <[email protected]>
Subject: Re: [Haskell-beginners] [IO String] to IO [String]
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAKVsE7tg1Os0=zsVrHSdiejmnxHsfD9eq-9j=9r2y+8m2kl...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
That makes perfect sense. Thanks for the detailed explanation.
On Sun, Mar 31, 2013 at 2:30 PM, Brent Yorgey <[email protected]>wrote:
> To elaborate a bit: you originally said "I don't like that the line
> processing I'm doing will have to be in the IO monad" -- but since you
> want the processing of the list of Strings to be interleaved with IO
> operations, you have no choice. Pure functions of type [String] ->
> [String] cannot have their evaluation interleaved with IO operations.
>
> Note that functions using lazy I/O such as getContents, readFile,
> etc. can create exceptions to this -- but these use unsafeInterleaveIO
> under the hood and are widely regarded as problematic. So you could
> try using unsafeInterleaveIO, but it is unsafe for a reason. I do not
> actually know what is required to ensure you are using it safely;
> perhaps someone else could elaborate on this.
>
> -Brent
>
> On Sun, Mar 31, 2013 at 01:48:23PM +0300, Ovidiu D wrote:
> > Right. I definitely want the lazy behavior.
> >
> > Thanks
> >
> >
> > On Sun, Mar 31, 2013 at 1:29 PM, Brent Yorgey <[email protected]
> >wrote:
> >
> > > Unfortunately, with the definition
> > >
> > > f = getLine : f
> > >
> > > this will not work. 'sequence f' has to do *ALL* the IO before you
> > > can process even the first String in the resulting list. Since it is
> > > infinite, it will just sit there reading lines forever but never
> > > letting you process them.
> > >
> > > I think in this case using [IO String] is actually a good solution.
> > >
> > > -Brent
> > >
> > > On Sun, Mar 31, 2013 at 12:24:33PM +0200, Nathan H?sken wrote:
> > > > Try
> > > >
> > > > sequence :: Monad m => [m a] -> m [a]
> > > >
> > > > I thinkg
> > > >
> > > > sequence f :: IO [String]
> > > >
> > > > should be what you want.
> > > >
> > > > On 03/31/2013 12:19 PM, Ovidiu D wrote:
> > > > >I have the function f which reads lines form the stdin and looks
> like
> > > this:
> > > > >
> > > > >f :: [IO String]
> > > > >f = getLine : f
> > > > >
> > > > >What I don't like is the fact that the line processing I'm doing
> will
> > > > >have to be in the IO Monad
> > > > >
> > > > >I would like to make this function to have the signature
> > > > >f : IO [String]
> > > > >...such that I can get rid of the IO monad and pass the pure string
> list
> > > > >to the processing function.
> > > > >
> > > > >Can I do this?
> > > > >
> > > > >Thanks
> > > > >
> > > > >
> > > > >_______________________________________________
> > > > >Beginners mailing list
> > > > >[email protected]
> > > > >http://www.haskell.org/mailman/listinfo/beginners
> > > > >
> > > >
> > > >
> > > > _______________________________________________
> > > > Beginners mailing list
> > > > [email protected]
> > > > http://www.haskell.org/mailman/listinfo/beginners
> > >
> > > _______________________________________________
> > > Beginners mailing list
> > > [email protected]
> > > http://www.haskell.org/mailman/listinfo/beginners
> > >
>
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
>
>
> _______________________________________________
> 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/20130331/43ee5f77/attachment-0001.htm>
------------------------------
Message: 4
Date: Sun, 31 Mar 2013 18:42:36 +0700
From: Kim-Ee Yeoh <[email protected]>
Subject: Re: [Haskell-beginners] [IO String] to IO [String]
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<capy+zdryxhpnkwy5b721o0tqdrkp1guuzj0wurbtav40hwc...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
On Sun, Mar 31, 2013 at 5:19 PM, Ovidiu D <[email protected]> wrote:
> I would like to make this function to have the signature
> f : IO [String]
> ...such that I can get rid of the IO monad and pass the pure string list to
> the processing function.
You could use:
getContents >>= lines :: IO [String]
-- Kim-Ee
------------------------------
Message: 5
Date: Sun, 31 Mar 2013 19:52:13 +0800
From: Lyndon Maydwell <[email protected]>
Subject: Re: [Haskell-beginners] [IO String] to IO [String]
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAM5QZtxrbDAeo8hNvzQgLTps=jupancpy3qkdr0fe7gxihm...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Depending on what you're doing with the lines, it may be worth checking out
the `interact` function as well :-)
On Sun, Mar 31, 2013 at 7:42 PM, Kim-Ee Yeoh <[email protected]> wrote:
> On Sun, Mar 31, 2013 at 5:19 PM, Ovidiu D <[email protected]> wrote:
> > I would like to make this function to have the signature
> > f : IO [String]
> > ...such that I can get rid of the IO monad and pass the pure string list
> to
> > the processing function.
>
> You could use:
>
> getContents >>= lines :: IO [String]
>
> -- Kim-Ee
>
> _______________________________________________
> 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/20130331/412e2f56/attachment-0001.htm>
------------------------------
Message: 6
Date: Sun, 31 Mar 2013 17:42:16 +0200
From: Nathan H?sken <[email protected]>
Subject: [Haskell-beginners] finding the cause of an error (here head:
empty list)
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hey,
I have written a program which, when executed produces:
Main: Prelude.head: empty list
Now, I can go through my program and replace all "head" with
(\a -> trace ("<line-nr>: length=" ++ (show (length a))) a)
Actually, I already did that, and by this I found the error.
But I wonder if there would have been an easier way?
Has anyone any debug advice how I could find out which call to "head"
causes this without so much typing work?
Thanks!
Nathan
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 57, Issue 45
*****************************************