gah you're right, @mtl had confuzzled me.
Well that changes things then, thanks.
Ross Paterson wrote:
> On Sat, Jul 31, 2010 at 10:56:31PM +1000, Tony Morris wrote:
>
>> -- Suppose some data type
>> newtype Inter a = Inter (Int -> a)
>>
>> -- and a monad transformer for that data type.
>> newt
On Sat, Jul 31, 2010 at 10:56:31PM +1000, Tony Morris wrote:
> -- Suppose some data type
> newtype Inter a = Inter (Int -> a)
>
> -- and a monad transformer for that data type.
> newtype InterT m a = InterT (m (Inter a))
The monad transformer should be Inter (m a).
___
Hello I have a question regarding monad transformers and how to design
an API with a transformer. I have a narrowed code example of the
question. Please see the questions in the comments below.
import Data.Monoid
import Control.Monad
-- Suppose some data type
newtype Inter a = Inter (Int -> a)
begin Andrew Coppin quotation:
> Roman Cheplyaka wrote:
> >See above:
> >-- Dynamic components may be retrieved with 'get', static components
> >-- with 'ask'.
> >
> >So you use ask to get some configuration variable (reader monad is used
> >for configuration in xmonad) and get/put/modify to deal w
> As I say, every time I've tried to do this, I end up writing a function to
> "run this stuff", and it typically takes a few hours to reach the point
> where it type-checks.
It took me a while the first time, but then I just learned the pattern
and I do it that way every time. Here's my pattern:
Roman Cheplyaka wrote:
* Andrew Coppin [2010-07-03 15:07:17+0100]
In my experience, defining a type representing several stacked monad
transformers is the easy part.
Of course it is. It wasn't my intention just to show you how easy it is
to define a newtype in Haskell :)
I just showe
* Andrew Coppin [2010-07-03 15:07:17+0100]
> Roman Cheplyaka wrote:
> >* Andrew Coppin [2010-07-03 14:20:14+0100]
> >>In my experience, using more than one monad transformer at once makes
> >>code utterly incomprehensible.
> >
> >See X monad (xmonad) for an counterexample.
> >
> >-- | The X monad
Roman Cheplyaka wrote:
* Andrew Coppin [2010-07-03 14:20:14+0100]
In my experience, using more than one monad transformer at once makes
code utterly incomprehensible.
See X monad (xmonad) for an counterexample.
-- | The X monad, 'ReaderT' and 'StateT' transformers over 'IO'
-- encaps
* Andrew Coppin [2010-07-03 14:20:14+0100]
> In my experience, using more than one monad transformer at once makes
> code utterly incomprehensible.
See X monad (xmonad) for an counterexample.
-- | The X monad, 'ReaderT' and 'StateT' transformers over 'IO'
-- encapsulating the window manager conf
On Mon, Oct 6, 2008 at 4:48 PM, Andrew Coppin
<[EMAIL PROTECTED]> wrote:
> Andrew Coppin wrote:
>>
>> I have some longwinded code that works, but I'm still thinking about how
>> to do this more elegantly. It looks like what I really need is something
>> like
>>
>> type M = StateT State (ResultSetT
Am Dienstag, 7. Oktober 2008 23:38 schrieb David Menendez:
> On Tue, Oct 7, 2008 at 5:07 PM, Daniel Fischer <[EMAIL PROTECTED]>
wrote:
> > Am Dienstag, 7. Oktober 2008 22:09 schrieb Andrew Coppin:
> >> Daniel Fischer wrote:
> >> > Maybe it is as simple as
> >> >
> >> > raw_bind (xs:xss) f = do
> >
On Tue, Oct 7, 2008 at 5:07 PM, Daniel Fischer <[EMAIL PROTECTED]> wrote:
> Am Dienstag, 7. Oktober 2008 22:09 schrieb Andrew Coppin:
>> Daniel Fischer wrote:
>> > Maybe it is as simple as
>> >
>> > raw_bind (xs:xss) f = do
>> > rsYs <- mapM f xs
>> > ~rsZ <- raw_bind xss f
>> > retu
Am Dienstag, 7. Oktober 2008 22:09 schrieb Andrew Coppin:
> Daniel Fischer wrote:
> > Am Dienstag, 7. Oktober 2008 20:27 schrieb Andrew Coppin:
> >> Basically, the core code is something like
> >>
> >> raw_bind :: (Monad m) => [[x]] -> (x -> m (ResultSet y)) -> m
> >> (ResultSet y)
> >> raw_bin
Daniel Fischer wrote:
Am Dienstag, 7. Oktober 2008 20:27 schrieb Andrew Coppin:
Basically, the core code is something like
raw_bind :: (Monad m) => [[x]] -> (x -> m (ResultSet y)) -> m
(ResultSet y)
raw_bind [] f = return empty
raw_bind (xs:xss) f = do
rsYs <- mapM f xs
rsZ <-
Am Dienstag, 7. Oktober 2008 20:27 schrieb Andrew Coppin:
> The good news: I managed to turn ResultSet into a monad transformer.
> Yay, me!
>
> The bad news: It generates the entire result set before returning
> anything to the caller.
>
> In other words, it works perfectly for finite result sets,
The good news: I managed to turn ResultSet into a monad transformer.
Yay, me!
The bad news: It generates the entire result set before returning
anything to the caller.
In other words, it works perfectly for finite result sets, and locks up
forever on infinite result sets. Since the entire *p
On Mon, Oct 6, 2008 at 9:48 PM, Andrew Coppin
<[EMAIL PROTECTED]> wrote:
> Andrew Coppin wrote:
>>
>> I have some longwinded code that works, but I'm still thinking about how
>> to do this more elegantly. It looks like what I really need is something
>> like
>>
>> type M = StateT State (ResultSetT
Hi Andrew,
On Mon, Oct 06, 2008 at 09:48:51PM +0100, Andrew Coppin wrote:
> data ResultSet x = Pack {unpack :: [[x]]} deriving (Eq)
Your ResultSet monad is roughly equivalent to
newtype Nat = Nat Int
instance Monoid Nat where
mempty = Nat 0
(Nat x) `mappend` (Nat y) = Nat (x+y)
type ResultSe
Andrew Coppin wrote:
If so, I guess that means I have to somehow construct ResultSetT. Is
there an easy way to do that, given that I already have ResultSet?
I haven't been following this thread closely, so forgive if this was
already discussed, but my understanding is that the answer is no, i
Andrew Coppin wrote:
I have some longwinded code that works, but I'm still thinking about
how to do this more elegantly. It looks like what I really need is
something like
type M = StateT State (ResultSetT (ErrorT ErrorType Identity))
Is that the correct ordering?
If so, I guess that means
David Menendez wrote:
So it might be possible to rewrite your code along these lines:
type M = StateT State []
run :: Foo -> M ()
runOr :: Foo -> Foo -> M ()
runOr x y = mplus (run x) (run y)
runAnd :: Foo -> Foo -> M ()
runAnd x y = run x >> run y
The type "StateT St
On Sun, May 08, 2005 at 07:54:43PM +0400, Max Vasin wrote:
> Hello!
>
> Suppose we have functions
>
> f :: ReaderT env monad1 rtype
> g :: Reader env rtype
>
> and we need to call g from f.
>
> Currently I write something like
>
> f = do env <- ask
>let r = runReader g env
>do
Hello!
Suppose we have functions
f :: ReaderT env monad1 rtype
g :: Reader env rtype
and we need to call g from f.
Currently I write something like
f = do env <- ask
let r = runReader g env
doSmth r
I don't like doing it this way (I need to get environment and
explicitly pass i
23 matches
Mail list logo