Clark Gaebel | 16 Apr 07:04 2013
Picon
Picon

primitive operations in StateT

Hi list!


I want to use MVectors in a StateT monad transformer.

How do I do that? StateT isn't a member of 'PrimMonad', and I have no idea how to make it one.

Regards,
  - Clark
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Ivan Lazar Miljenovic | 16 Apr 07:42 2013
Picon

Re: primitive operations in StateT

On 16 April 2013 15:04, Clark Gaebel <cgaebel <at> uwaterloo.ca> wrote:
> Hi list!
>
> I want to use MVectors in a StateT monad transformer.
>
> How do I do that? StateT isn't a member of 'PrimMonad', and I have no idea
> how to make it one.

You can use Control.Monad.Trans.lift to lift the PrimMonad operations
to PrimMonad m => StateT s m

>
> Regards,
>   - Clark
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

--

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic <at> gmail.com
http://IvanMiljenovic.wordpress.com
Clark Gaebel | 16 Apr 07:56 2013
Picon
Picon

Re: primitive operations in StateT

The monad my code is currently written in is:


type MC = MCT Identity -- where MCT is the monad transformer version of it.

I have two options for threading state through this:

    MCT (ST s) a
    StateT s MC a

The first option would work if I had some function with the signature

MCT Identity a -> MCT (ST s) a

but I know of no such function, and the second one would work if I had some way of making StateT a member of PrimMonad.

Can I see an example with 'lift'?

  - Clark

On Tuesday, April 16, 2013, Ivan Lazar Miljenovic wrote:
On 16 April 2013 15:04, Clark Gaebel <cgaebel <at> uwaterloo.ca> wrote:
> Hi list!
>
> I want to use MVectors in a StateT monad transformer.
>
> How do I do that? StateT isn't a member of 'PrimMonad', and I have no idea
> how to make it one.

You can use Control.Monad.Trans.lift to lift the PrimMonad operations
to PrimMonad m => StateT s m

>
> Regards,
>   - Clark
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



--
Ivan Lazar Miljenovic
Ivan.Miljenovic <at> gmail.com
http://IvanMiljenovic.wordpress.com
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Clark Gaebel | 16 Apr 08:08 2013
Picon
Picon

Re: primitive operations in StateT

*sigh* nevermind.


I found it. Turns out there was:
liftMCT :: (Monad m) => MC a -> MCT m a
in an unexported module in the monte-carlo package all along. I just need to export it and I'll be good to go.

Thanks for your help!
  - Clark

On Tuesday, April 16, 2013, Clark Gaebel wrote:
The monad my code is currently written in is:

type MC = MCT Identity -- where MCT is the monad transformer version of it.

I have two options for threading state through this:

    MCT (ST s) a
    StateT s MC a

The first option would work if I had some function with the signature

MCT Identity a -> MCT (ST s) a

but I know of no such function, and the second one would work if I had some way of making StateT a member of PrimMonad.

Can I see an example with 'lift'?

  - Clark

On Tuesday, April 16, 2013, Ivan Lazar Miljenovic wrote:
On 16 April 2013 15:04, Clark Gaebel <cgaebel <at> uwaterloo.ca> wrote:
> Hi list!
>
> I want to use MVectors in a StateT monad transformer.
>
> How do I do that? StateT isn't a member of 'PrimMonad', and I have no idea
> how to make it one.

You can use Control.Monad.Trans.lift to lift the PrimMonad operations
to PrimMonad m => StateT s m

>
> Regards,
>   - Clark
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



--
Ivan Lazar Miljenovic
Ivan.Miljenovic <at> gmail.com
http://IvanMiljenovic.wordpress.com
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Ivan Lazar Miljenovic | 16 Apr 08:29 2013
Picon

Re: primitive operations in StateT

On 16 April 2013 15:56, Clark Gaebel <cgaebel <at> uwaterloo.ca> wrote:
> The monad my code is currently written in is:
>
> type MC = MCT Identity -- where MCT is the monad transformer version of it.
>
> I have two options for threading state through this:
>
>     MCT (ST s) a
>     StateT s MC a
>
> The first option would work if I had some function with the signature
>
> MCT Identity a -> MCT (ST s) a
>
> but I know of no such function, and the second one would work if I had some
> way of making StateT a member of PrimMonad.
>
> Can I see an example with 'lift'?

You should just be able to use lift to convert any PrimMonad action
into your MCT-based monad as long as MCT is an instance of the
MonadTrans class.

i.e. if `foo :: (PrimMonad m) => m a' and MCT is an instance of
MonadTrans, then you can do `lift foo :: (PrimMonad m) => MCT m a', or
`lift (lift foo) :: (PrimMonad m) => MCT (StateT s m) a'.

As another option, I have an as-yet-unreleased library to let you
avoid having to do lift . lift for PrimMonad-based actions:
http://hub.darcs.net/ivanm/monad-prim

>
>   - Clark
>
> On Tuesday, April 16, 2013, Ivan Lazar Miljenovic wrote:
>>
>> On 16 April 2013 15:04, Clark Gaebel <cgaebel <at> uwaterloo.ca> wrote:
>> > Hi list!
>> >
>> > I want to use MVectors in a StateT monad transformer.
>> >
>> > How do I do that? StateT isn't a member of 'PrimMonad', and I have no
>> > idea
>> > how to make it one.
>>
>> You can use Control.Monad.Trans.lift to lift the PrimMonad operations
>> to PrimMonad m => StateT s m
>>
>> >
>> > Regards,
>> >   - Clark
>> >
>> > _______________________________________________
>> > Haskell-Cafe mailing list
>> > Haskell-Cafe <at> haskell.org
>> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>> >
>>
>>
>>
>> --
>> Ivan Lazar Miljenovic
>> Ivan.Miljenovic <at> gmail.com
>> http://IvanMiljenovic.wordpress.com

--

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic <at> gmail.com
http://IvanMiljenovic.wordpress.com

Gmane