[Haskell-cafe] Combine `StateT` and `InputT` to maintain state on Ctrl-C interrupt

mikael.brockman at gmail.com mikael.brockman at gmail.com
Wed Aug 12 15:55:29 UTC 2015


Tom Ellis <tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> writes:

> On Wed, Aug 12, 2015 at 04:26:59PM +0200, haskell at stefan-klinger.de wrote:
>> At first I thought I had stacked the `StateT` and `InputT` in the
>> wrong order.  But changing from `InputT (StateT Int IO) ()` to `StateT
>> Int (InputT IO) ()` seems not to change anything (which really gives
>> me the creeps).
>
> InputT is essentially ReaderT
>
>     http://hackage.haskell.org/package/haskeline-0.7.2.1/docs/src/System-Console-Haskeline-InputT.html#InputT
>
> so it's not surprising that the order has no effect.   Reader commutes with
> State.

Note in the source there that the state of the Haskeline stuff itself
uses "ReaderT (IO _) vs StateT so that exceptions (e.g. ctrl-c) don't
cause us to lose the existing state." If there was a more elegant
solution, Haskeline itself could use it, I guess? So it's probably at
least hard to do generally for any exception occurring in
the application?

But could one get away with using `handle` at the particular sites where
one expects to be interrupted, e.g. around the call to `threadDelay`?



More information about the Haskell-Cafe mailing list