Send Beginners mailing list submissions to beginners@haskell.org 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 beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. [IO String] to IO [String] (Ovidiu D) 2. Quickcheck2 - writing a modifier for test data (Nathan H?sken) 3. Re: [IO String] to IO [String] (Tony Morris) 4. Re: [IO String] to IO [String] (Nathan H?sken) 5. Re: [IO String] to IO [String] (Brent Yorgey) 6. Re: Quickcheck2 - writing a modifier for test data (Brent Yorgey) 7. Re: [IO String] to IO [String] (Ovidiu D) ---------------------------------------------------------------------- Message: 1 Date: Sun, 31 Mar 2013 13:19:41 +0300 From: Ovidiu D <ovidiud...@gmail.com> Subject: [Haskell-beginners] [IO String] to IO [String] To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Message-ID: <CAKVsE7vhTPDuDfN7fQc7N48ibCUQ=m5tegpc2rkkcx7ijuc...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130331/3a8b4aa0/attachment-0001.htm> ------------------------------ Message: 2 Date: Sun, 31 Mar 2013 12:21:48 +0200 From: Nathan H?sken <nathan.hues...@posteo.de> Subject: [Haskell-beginners] Quickcheck2 - writing a modifier for test data To: beginners@haskell.org Message-ID: <51580e3c.6080...@posteo.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hey, Using quickcheck2 I want to generate test data, that is a tuple of integers where both elements are >=0 and < 8. So I am trying to write a modifier (in the sense of the modifiers found in Modifiers.hs): newtype ValidPos = ValidPos Pos deriving Show instance Arbitrary ValidPos where arbitrary = do x <- elements [0..7] y <- elements [0..7] return (ValidPos (x,y)) prop_dummy (ValidPos pos) = fst pos > 0 tests = [ testGroup "Tests" [ testProperty "dummy" prop_dummy ] ] main = defaultMain tests doing so gives me this error: No instance for (QuickCheck-2.4.2:Test.QuickCheck.Arbitrary.Arbitrary ValidPos) arising from a use of `testProperty' Possible fix: add an instance declaration for (QuickCheck-2.4.2:Test.QuickCheck.Arbitrary.Arbitrary ValidPos) In the expression: testProperty "dummy" prop_dummy In the second argument of `testGroup', namely `[testProperty "dummy" prop_dummy]' In the expression: testGroup "Tests" [testProperty "dummy" prop_dummy] I declared the instance, why canit not be found? Thanks! Nathan ------------------------------ Message: 3 Date: Sun, 31 Mar 2013 20:23:14 +1000 From: Tony Morris <tonymor...@gmail.com> Subject: Re: [Haskell-beginners] [IO String] to IO [String] To: beginners@haskell.org Message-ID: <51580e92.6010...@gmail.com> Content-Type: text/plain; charset="iso-8859-1" You can use sequence which will turn your [IO String] into a IO [String]. If you want to "map a function" along the way, you can use mapM (or traverse): That is: mapM :: (String -> IO b) -> [IO String] -> IO [b] For further reading, there is a paper about this function called The Essence of the Iterator Pattern. On 31/03/13 20:19, 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 > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners -- Tony Morris http://tmorris.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130331/474ce7d9/attachment-0001.htm> ------------------------------ Message: 4 Date: Sun, 31 Mar 2013 12:24:33 +0200 From: Nathan H?sken <nathan.hues...@posteo.de> Subject: Re: [Haskell-beginners] [IO String] to IO [String] To: beginners@haskell.org Message-ID: <51580ee1.7050...@posteo.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed 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 > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > ------------------------------ Message: 5 Date: Sun, 31 Mar 2013 06:29:22 -0400 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] [IO String] to IO [String] To: beginners@haskell.org Message-ID: <20130331102922.ga31...@seas.upenn.edu> Content-Type: text/plain; charset=iso-8859-1 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 > >Beginners@haskell.org > >http://www.haskell.org/mailman/listinfo/beginners > > > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners ------------------------------ Message: 6 Date: Sun, 31 Mar 2013 06:30:58 -0400 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] Quickcheck2 - writing a modifier for test data To: beginners@haskell.org Message-ID: <20130331103058.gb31...@seas.upenn.edu> Content-Type: text/plain; charset=iso-8859-1 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 ------------------------------ Message: 7 Date: Sun, 31 Mar 2013 13:48:23 +0300 From: Ovidiu D <ovidiud...@gmail.com> Subject: Re: [Haskell-beginners] [IO String] to IO [String] To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Message-ID: <CAKVsE7sLTL=hmgfkjuwm5mahftkvf4ebrxmvfyvjmdgsdzw...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Right. I definitely want the lazy behavior. Thanks On Sun, Mar 31, 2013 at 1:29 PM, Brent Yorgey <byor...@seas.upenn.edu>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 > > >Beginners@haskell.org > > >http://www.haskell.org/mailman/listinfo/beginners > > > > > > > > > _______________________________________________ > > Beginners mailing list > > Beginners@haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130331/a6076cac/attachment.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 57, Issue 44 *****************************************