haskell / haskeline

A Haskell library for line input in command-line programs.
https://hackage.haskell.org/package/haskeline
BSD 3-Clause "New" or "Revised" License
221 stars 75 forks source link

mapInputT doesn't allow changing base monad? #65

Closed remexre closed 7 years ago

remexre commented 7 years ago

Right now, mapInputT has the type:

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

As I understand it (I'm new to transformers, so correct me if I'm wrong), the type should be:

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

in order to allow for changing the base monad.

judah commented 7 years ago

I think it's not possible as the monad is defined now. The type of InputT is essentially InputT m a = InputT (r -> CompletionFunc m -> m a): https://github.com/judah/haskeline/blob/master/System/Console/Haskeline/Completion.hs

where CompletionFunc m is defined here: https://github.com/judah/haskeline/blob/master/System/Console/Haskeline/Completion.hs

A much simpler example is:

newtype InputT m a = InputT (m () -> m a)

for which you can't write a mapInputT with the type you suggested.

Do you have a specific use case for such a mapInputT? If so, maybe we can find a different combinator that would solve the same problem.

remexre commented 7 years ago

I was trying to do InputT MyNewtype () -> InputT IO (State, Either Err a), but I actually rewrote to avoid that; still, it seems like something that ought to exist... If it's not possible though, you can close this; I just wanted to be sure.