On Sat, May 24, 2008 at 3:39 AM, Bulat Ziganshin [EMAIL PROTECTED]
wrote:
Hello Olivier,
Saturday, May 24, 2008, 5:37:32 AM, you wrote:
(|) = flip (.)
I even started to use it in my code and then stopped. It may be a
stupid concern but as many optimizations performed by GHC are made
On Fri, May 23, 2008 at 2:20 PM, Thomas Hartman [EMAIL PROTECTED] wrote:
The big benefit I got from using the State Monad was that I was able to
reorder the functions by just copy/pasting the function name from one
place to another.
I don't understand... why do you need state to do this?
On Wed, May 21, 2008 at 6:19 PM, Dmitri O.Kondratiev [EMAIL PROTECTED]
wrote:
-- Then we can use this State object (returned by getAny) in a function
generating random values such as:
makeRnd :: StdGen - (Int, StdGen)
makeRnd = runState (do
y - getAny
So, are there any other simple motivating examples that show what
state is really good for?
Here's an example from some code that I'm (trying to) write; I am
writing a DSL for the Povray Scene Description Language. This part of
my program creates a `String' which holds a piece of Povray SDL
2008/5/22 Olivier Boudry [EMAIL PROTECTED]:
On Wed, May 21, 2008 at 6:19 PM, Dmitri O.Kondratiev [EMAIL PROTECTED]
wrote:
-- Then we can use this State object (returned by getAny) in a function
generating random values such as:
makeRnd :: StdGen - (Int, StdGen)
makeRnd = runState (do
I would be interested in seeing good motivating examples for use of
the state monad, other than that example from All About Monads.
Okay, it's good for randomness. What else?
Reading the source code for State, I think I saw an example about
using state to uniquely label elements of a tree with
Thomas Hartman wrote:
I would be interested in seeing good motivating examples for use of
the state monad...
Okay, it's good for randomness. What else?
...I saw an example about
using state to uniquely label elements of a tree
So, are there any other simple motivating examples that show what
Thanks everybody for your help!
Oliver, you provided an excellent write-up on State monad without
going into 'scary' :) details, great work indeed!
Alas, in this case I need the details, and in particular the most scary
ones!
So let's start with fundamental and most intriguing (to me)
On Wed, May 21, 2008 at 8:42 AM, Dmitri O.Kondratiev [EMAIL PROTECTED]
wrote:
So let's start with fundamental and most intriguing (to me) things:
getAny :: (Random a) = State StdGen a
getAny = do g - get -- magically get the current StdGen
First line above declares a data type:
State
Dmitri O.Kondratiev wrote:
Thanks everybody for your help!
Oliver, you provided an excellent write-up on State monad without
going into 'scary' :) details, great work indeed!
Alas, in this case I need the details, and in particular the most scary
ones!
So let's start with fundamental
State is a data type. As any other data type it can be instantiated. State
instance is a structure of one record that contains (\s -(a,s)) lambda
function. This function can be parametrized by types of its arguments 's'
and 'a'. I don't see magic here :)
Ok, then from declaration:
getAny ::
Jules,
Stupid question, please bear with me:
x :: Int -- x declared, but not constructed
x = 1 -- x constructed
s1 :: State StdGen a -- s1 declared, yes, but why s1 is *also already
constructed* ?
On Wed, May 21, 2008 at 6:54 PM, Jules Bean [EMAIL PROTECTED] wrote:
Dmitri O.Kondratiev wrote:
Dmitri O.Kondratiev wrote:
Jules,
Stupid question, please bear with me:
x :: Int -- x declared, but not constructed
x = 1 -- x constructed
s1 :: State StdGen a -- s1 declared, yes, but why s1 is *also already
constructed* ?
it's not.
it's constructed when you do
s1 = return 1
... or ...
-- Jules, Oliver, thanks! Things are getting clarified, I hope.
-- Let me summarize how I now understand getAny operation, please correct me
if I am wrong.
getAny :: (Random a) = State StdGen a
getAny = do g - get
(x,g') - return $ random g
put g'
return x
{--
2008/5/19 Dmitri O.Kondratiev [EMAIL PROTECTED]:
I am trying to understand State monad example15 at:
http://www.haskell.org/all_about_monads/html/statemonad.html
Hi Dmitri,
I'm not sure you need to understand everything about Monad and do-notation
to use the State Monad. So I will try to
Dmitri,
Excellent questions. There's one step you're missing. Most of your
questions revolve around 'foo - bar' constructs within a monad. I
would suggest that you review the de-sugaring rules at
http://en.wikibooks.org/wiki/Haskell/Syntactic_sugar#Do_and_proc_notation
and see if that helps you
Hi Dmitri. I'm just going to ramble on about what I know and how I
think of things, and maybe you'll pick something up :-)
On 5/19/08, Dmitri O.Kondratiev [EMAIL PROTECTED] wrote:
getAny :: (Random a) = State StdGen a
getAny = do g - get
(x,g') - return $ random g
17 matches
Mail list logo