JP Moresmau | 1 Nov 09:46 2013
Picon

SYB: queries using IO Monad

Hello cafe,

I have code that works well using the syb package, and the ext1Q, extQ and gmapQ functions. This code that a Data and transforms it into something else.
However I need to make a change, and this change involves calling a function in the IO monad (the function is from another library so I have no choice). However, the ext1Q, extQ and gmapQ functions have no monadic equivalent. There seems to be monadic transformation (from a to different a) but no monadic queries (from a to b).
Do I have to rewrite these functions myself to work with monadic queries (it at all possible) or is there a better way? I've seen some functions that work with monads and MonadPlus, but I don't see anything that would work with IO.
So far I've checked that the IO() function I'm calling does the job by using unsafePerformIO, but I know that's a sin and I'd like to find a better way!

Thanks!

JP

--
JP Moresmau
http://jpmoresmau.blogspot.com/
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Andres Löh | 1 Nov 10:00 2013

Re: SYB: queries using IO Monad

Hi.

> However, the ext1Q, extQ and gmapQ functions have no monadic equivalent.
> There seems to be monadic transformation (from a to different a) but no
> monadic queries (from a to b).
> Do I have to rewrite these functions myself to work with monadic queries (it
> at all possible) or is there a better way? I've seen some functions that
> work with monads and MonadPlus, but I don't see anything that would work
> with IO.

I think the idea is that the Q functions don't need a monadic
counterpart because they can already be used at a monadic result type.

Cheers,
  Andres

--

-- 
Andres Löh, Haskell Consultant
Well-Typed LLP, http://www.well-typed.com
JP Moresmau | 1 Nov 11:07 2013
Picon

Re: SYB: queries using IO Monad

You're perfectly right Andres. ext1Q and extQ work well with monadic result type. I can't get gmapQ to work though, but I seem to in fact not need it, so I've removed its usage totally.

Thanks a million!

JP


On Fri, Nov 1, 2013 at 10:00 AM, Andres Löh <andres <at> well-typed.com> wrote:
Hi.

> However, the ext1Q, extQ and gmapQ functions have no monadic equivalent.
> There seems to be monadic transformation (from a to different a) but no
> monadic queries (from a to b).
> Do I have to rewrite these functions myself to work with monadic queries (it
> at all possible) or is there a better way? I've seen some functions that
> work with monads and MonadPlus, but I don't see anything that would work
> with IO.

I think the idea is that the Q functions don't need a monadic
counterpart because they can already be used at a monadic result type.

Cheers,
  Andres

--
Andres Löh, Haskell Consultant
Well-Typed LLP, http://www.well-typed.com



--
JP Moresmau
http://jpmoresmau.blogspot.com/
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
JP Moresmau | 1 Nov 11:59 2013
Picon

Re: SYB: queries using IO Monad

Well, I'm stupid, I only need to combine sequence with gmapQ and it works! Thanks Andres!

JP


On Fri, Nov 1, 2013 at 11:07 AM, JP Moresmau <jpmoresmau <at> gmail.com> wrote:
You're perfectly right Andres. ext1Q and extQ work well with monadic result type. I can't get gmapQ to work though, but I seem to in fact not need it, so I've removed its usage totally.

Thanks a million!

JP


On Fri, Nov 1, 2013 at 10:00 AM, Andres Löh <andres <at> well-typed.com> wrote:
Hi.

> However, the ext1Q, extQ and gmapQ functions have no monadic equivalent.
> There seems to be monadic transformation (from a to different a) but no
> monadic queries (from a to b).
> Do I have to rewrite these functions myself to work with monadic queries (it
> at all possible) or is there a better way? I've seen some functions that
> work with monads and MonadPlus, but I don't see anything that would work
> with IO.

I think the idea is that the Q functions don't need a monadic
counterpart because they can already be used at a monadic result type.

Cheers,
  Andres

--
Andres Löh, Haskell Consultant
Well-Typed LLP, http://www.well-typed.com






--
JP Moresmau
http://jpmoresmau.blogspot.com/
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane