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:  State Monad - Not in scope: data constructor `State'
      (Hugo Ferreira)


----------------------------------------------------------------------

Message: 1
Date: Mon, 31 Oct 2011 09:38:11 +0000
From: Hugo Ferreira <h...@inescporto.pt>
Subject: Re: [Haskell-beginners] State Monad - Not in scope: data
        constructor `State'
To: Brent Yorgey <byor...@seas.upenn.edu>
Cc: beginners@haskell.org
Message-ID: <4eae6c83.2060...@inescporto.pt>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 10/29/2011 09:09 PM, Brent Yorgey wrote:
> On Sat, Oct 29, 2011 at 08:48:28PM +0100, Hugo Ferreira wrote:
>> Hello,
>>
>> I am trying to use some State Monad code
>> in order to learn about this. However in
>> GHCi I cannot use the "State" constructor.
>>
>> import qualified Control.Monad.State
>>
>>> :{
>> | let fromStoAandS c | c `mod` 5 == 0 = ("foo",c+1)
>> |                | otherwise      = ("bar",c+1)
>> | :}
>>> :t fromStoAandS
>>> fromStoAandS :: Integral t =>  t ->  ([Char], t)
>>
>>> :{
>> | let stateIntString = State fromStoAandS
>>> Prelude Control.Monad.State| :}
>>>
>>> <interactive>:1:22: Not in scope: data constructor `State'
>>
>> I have found a message stating that this is not possible
>> because their is "no State data constructor", it is only "defined
>> to be a type alias".
>
> That is correct.  State used to be defined directly; now it is just an
> alias for StateT s Identity.  You don't really have to worry about
> what this means, but the point is that there is no longer a real State
> constructor.
>
> The author of the message then says we should use:
>>
>> http://hackage.haskell.org/packages/archive/transformers/latest/doc/html/Control-Monad-Trans-State-Lazy.html#v:state
>>
>> instead. Still lost however.
>> So, how do I create the "Sate" above?
>
> You simply replace 'State' by 'state', a function provided to act like
> the old State constructor.  So you write
>
>    let stateIntString = state fromStoAandS

Ok, Got it.

Thanks,
Hugo F.

>
> -Brent
>
> _______________________________________________
> 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


End of Beginners Digest, Vol 40, Issue 49
*****************************************

Reply via email to