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. Re: Overloading resolution with numbers (damodar kulkarni) 2. Re: Combining the Rand and State monads (Brent Yorgey) 3. Re: Combining the Rand and State monads (Amy de Buitl?ir) ---------------------------------------------------------------------- Message: 1 Date: Thu, 5 Apr 2012 20:29:41 +0530 From: damodar kulkarni <kdamodar2...@gmail.com> Subject: Re: [Haskell-beginners] Overloading resolution with numbers To: j.romi...@gmail.com Cc: Amy de Buitl?ir <a...@nualeargais.ie> Message-ID: <cad5hsyqczirf6ztdppyew9jwhfm7ojnsvmptuudydqkohcp...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" See this: Prelude> :t 2.3 2.3 :: Fractional a => a Hope this helps. On Thu, Apr 5, 2012 at 7:24 PM, <j.romi...@gmail.com> wrote: > On Thu, Apr 05, 2012 at 01:18:39PM +0000, Amy de Buitl?ir wrote: > > <j.romildo <at> gmail.com> writes: > > > Why does (read "2" + 1) works, but (read "2.3" + 1) fail at runtime? > > > > Try this: > > > > read "2.3" + 1 :: Float > > > > Or this: > > > > read "2.3" + 1.0 > > > > The reason that your version didn't work is because GHCi is guessing > that you > > want the read operation to parse an Integer, since you're adding it to 1. > > This is explanation does not seem to be enough once we consider the type > of the literal 1: > > Prelude> :t 1 > 1 :: Num a => a > > That is, the literal 1 is overloaded to any numeric type. It is not > necessarily an Integer. > > Romildo > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -- Thanks and regards, -Damodar Kulkarni -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120405/60cb00d5/attachment-0001.htm> ------------------------------ Message: 2 Date: Thu, 5 Apr 2012 13:52:47 -0400 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] Combining the Rand and State monads To: beginners@haskell.org Message-ID: <20120405175247.ga24...@seas.upenn.edu> Content-Type: text/plain; charset=iso-8859-1 On Thu, Apr 05, 2012 at 10:42:20AM +0000, Amy de Buitl?ir wrote: > I'm trying to develop a very simple simulation framework. A simulation > consists > of a list of models. Models generate output events based on an input event. > Here > is what I have currently (it works fine). > > > modelT :: Model g > modelT _ = do > s <- get > put $ s ++ " R" > n <- HOW DO I GET A RANDOM NUMBER???? > return [n] I assume you are using the MonadRandom package? Getting a random number is as simple as doing something like "getRandomR ('A','Z')" (or using any other method from the MonadRandom class [1]). There is an instance MonadRandom m => MonadRandom (StateT s m), so calls to getRandom, getRandomR, etc. are automatically lifted into your Model monad. Your problem seems to be the type you have given to modelT: it claims that it will work for *any* type g but this is not so; g must represent a pseudorandom number generator. This works: modelT :: RandomGen g => Model g modelT _ = do s <- get put $ s ++ " R" n <- getRandomR ('A', 'Z') return [n] -Brent [1] http://hackage.haskell.org/packages/archive/MonadRandom/0.1.6/doc/html/Control-Monad-Random-Class.html ------------------------------ Message: 3 Date: Thu, 5 Apr 2012 21:55:11 +0000 (UTC) From: Amy de Buitl?ir <a...@nualeargais.ie> Subject: Re: [Haskell-beginners] Combining the Rand and State monads To: beginners@haskell.org Message-ID: <loom.20120405t235230-...@post.gmane.org> Content-Type: text/plain; charset=us-ascii Brent Yorgey <byorgey <at> seas.upenn.edu> writes: > Your problem seems to be the type you have given to modelT: it claims > that it will work for *any* type g but this is not so; g must > represent a pseudorandom number generator. This works: D'oh! A dumb mistake on my part. Thank you, Brent. ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 46, Issue 7 ****************************************