Many of the tutorials on the state monad seem to suggest that you can use State as a data constructor, but I can't get this to work. E.g. in ghci after :m Control.Monad.State I can let f = (\x -> (x,x)) let y = state f but if I, let z = State f I get an error message: Not in scope: data constructor `State'. Can someone please explain? Thanks, Britt
On Mon, Feb 14, 2011 at 8:11 PM, Britt Anderson <britt.uwaterloo@gmail.com> wrote:
Many of the tutorials on the state monad seem to suggest that you can use State as a data constructor, but I can't get this to work. E.g. in ghci after :m Control.Monad.State I can
let f = (\x -> (x,x)) let y = state f
but if I,
let z = State f
I get an error message: Not in scope: data constructor `State'.
Can someone please explain?
Thanks, Britt
GHCi doesn't load all Haskell modules by default. It only loads Prelude. You'll have to load them by hand. Use :m +Control.Monad.State -- Mihai
On Mon, Feb 14, 2011 at 8:18 PM, Mihai Maruseac <mihai.maruseac@gmail.com> wrote:
On Mon, Feb 14, 2011 at 8:11 PM, Britt Anderson <britt.uwaterloo@gmail.com> wrote:
Many of the tutorials on the state monad seem to suggest that you can use State as a data constructor, but I can't get this to work. E.g. in ghci after :m Control.Monad.State I can
let f = (\x -> (x,x)) let y = state f
but if I,
let z = State f
I get an error message: Not in scope: data constructor `State'.
Can someone please explain?
Thanks, Britt
GHCi doesn't load all Haskell modules by default. It only loads Prelude. You'll have to load them by hand. Use
:m +Control.Monad.State
Also, see if you have the mtl library installed (or Transformers). -- Mihai
Actually, I can load the module and I have mtl. I just don't understand why I can use State as a data constructor, but the inverse of runState, i.e. state works just fine. Has this library/package been reconfigured from when most people were writing tutorials? On Mon, Feb 14, 2011 at 1:19 PM, Mihai Maruseac <mihai.maruseac@gmail.com>wrote:
On Mon, Feb 14, 2011 at 8:18 PM, Mihai Maruseac <mihai.maruseac@gmail.com> wrote:
On Mon, Feb 14, 2011 at 8:11 PM, Britt Anderson <britt.uwaterloo@gmail.com> wrote:
Many of the tutorials on the state monad seem to suggest that you can use State as a data constructor, but I can't get this to work. E.g. in ghci after :m Control.Monad.State I can
let f = (\x -> (x,x)) let y = state f
but if I,
let z = State f
I get an error message: Not in scope: data constructor `State'.
Can someone please explain?
Thanks, Britt
GHCi doesn't load all Haskell modules by default. It only loads Prelude. You'll have to load them by hand. Use
:m +Control.Monad.State
Also, see if you have the mtl library installed (or Transformers).
-- Mihai
On Monday 14 February 2011 19:23:43, Britt Anderson wrote:
Actually, I can load the module and I have mtl. I just don't understand why I can use State as a data constructor, but the inverse of runState, i.e. state works just fine. Has this library/package been reconfigured from when most people were writing tutorials?
Exactly that. As of mtl-2.*, mtl is now a wrapper around transformers and no longer an independent library. One change which broke a lot of tutorials (and some code) is that State is no longer a separate datatype. (State s) is now a type synonym for (StateT s Identity), similarly for Reader, Writer. Those parts of the tutorials whcih don't use the data-constructor should work unchanged, though.
In the latest version of mtl, there is no State data constructor. http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Mona... State<http://hackage.haskell.org/packages/archive/transformers/latest/doc/html/Control-Monad-Trans-State-Lazy.html#t:State>is defined to be a type alias to the application of Identity monad to the StateT monad transformer. As you've already discovered, you need to use state<http://hackage.haskell.org/packages/archive/transformers/latest/doc/html/Control-Monad-Trans-State-Lazy.html#v:state> instead. HTH, Ozgur On 14 February 2011 18:11, Britt Anderson <britt.uwaterloo@gmail.com> wrote:
Many of the tutorials on the state monad seem to suggest that you can use State as a data constructor, but I can't get this to work. E.g. in ghci after :m Control.Monad.State I can
let f = (\x -> (x,x)) let y = state f
but if I,
let z = State f
I get an error message: Not in scope: data constructor `State'.
Can someone please explain?
Thanks, Britt
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Ozgur Akgun
participants (4)
-
Britt Anderson -
Daniel Fischer -
Mihai Maruseac -
Ozgur Akgun