Arrows that are also Functors
Maciej Piechotka
uzytkownik2 at gmail.com
Tue Apr 26 21:38:32 CEST 2011
On Tue, 2011-04-26 at 15:13 -0400, Tyson Whitehead wrote:
> On April 26, 2011 13:50:10 Maciej Marcin Piechotka wrote:
> > On Tue, 2011-04-19 at 23:48 -0400, Tyson Whitehead wrote:
> > > On April 19, 2011 23:22:12 Tyson Whitehead wrote:
> > > > ArrowLoop from MonadFix
> > > >
> > > > loop' f = fst' .' loop'' (f .' arr' (second snd))
> > > >
> > > > where loop'' f = mfix (\y -> f .' arr' (,y))
> > >
> > > BTW haskellers, I've been wondering if mfix would better be defined as
> > >
> > > mfix' :: (m a -> m a) -> m a
> > >
> > > where "mfix' f = mfix (f . pure)" for the computational monads. The
> > > advantage being you can give a useful definition for structural monads
> > > as well.
> >
> > What would be the difference with fix?
>
> For the IO monad, for example, normal fix would give you an IO value which
> would repeat the underlying IO action. The mfix' above give you the result of
> the first run of the IO action lazily bound in an IO context. Consider
>
> Prelude> fix $ fmap (1:)
> ... never returns (overflows the stack and dies) ...
>
> Prelude> mfix' $ fmap (1:)
> ... returns "return $ repeat 1" ...
>
> The difference between mfix and mfix' being you can't (or at least I couldn't)
> implement it for non-singleton monads such as list.
But... list is monad fix. From base:
> instance MonadFix [] where
> mfix f = case fix (f . head) of
> [] -> []
> (x:_) -> x : mfix (tail . f)
Prelude> mfix (fmap (1:) . return)
[1,1,1,1,...
> The problem was mfix had
> to do a map like operation across the underlying structure to invoke the
> function on the lazily bound singletons before any of the structure existed.
>
> Cheers! -Tyson
I still cannot find any use which would not be covered by either mfix or fix.
Regards
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/libraries/attachments/20110426/4aace76e/attachment.pgp>
More information about the Libraries
mailing list