Ticket #117 (closed enhancement: fixed)

Opened 3 years ago

Last modified 2 years ago

mapInputT

Reported by: guest Owned by:
Priority: major Milestone:
Version: Keywords:
Cc: tora@…

Description

I have a need for a mapInputT :: (m a -> n b) -> InputT m a -> InputT n b function, which should provide an idiomatic way to (e.g.) layer haskeline over some haskellDB usage (which is IO specific - transaction :: IO a -> IO a ).

This should be analagous to mapReaderT, mapStateT etc.

It should be short, but tricky to write. If I can come up with an implementation I'll attach it here.

Change History

Changed 3 years ago by guest

Having just dug through the source code, I think the use of (Settings m) in the definition of InputT will restrict this to: mapInputT :: (m a -> m b) -> InputT m a -> InputT m b , or some variation thereof.

Changed 3 years ago by guest

Ah, after some more investigation, you use a custom StateT transformer in the definition of InputT so this isn't straightforward at all.

Changed 3 years ago by judah

Would it be enough to have a function like this?

mapInputT :: (forall b . m b -> n b) -> InputT m a -> InputT n a

Internally, it could be implemented using:

mapStateT :: (forall b . m b -> n b) -> StateT s m a -> StateT s n a
mapStateT f (StateT m) = StateT (\s -> f (m s))

Changed 2 years ago by judah

  • status changed from new to closed
  • resolution set to fixed

Haskeline-0.7.0.0 provides mapInputT. Similar functionality is also provided in System.Console.Haskeline.MonadException, which now provides a more general API.

Note: See TracTickets for help on using tickets.