[Haskell-cafe] Stuck on design problem

Miguel Mitrofanov miguelimo38 at yandex.ru
Mon May 20 14:38:25 CEST 2013


:t runMemLog (runTransitionT $ demo 1)
runMemLog (runTransitionT $ demo 1)
  :: MonadLog (MemLog a) () => Log a -> ((), [Command ()])

That means, that "foo", if you manage to compile it, would have type MonadLog (MemLog a) () => ((), [Command ()]). That means that in each call for foo it would be used as something of the type ((), [Command ()]), therefore giving no indication of which "a" should be used. The fact that there is only one instance of MonadLog (MemLog a) () - namely, the one with a = () - doesn't matter, as there could be others in the future. That's why GHC is complaining.

So, you have to provide such indication by youself, replacing IntMap.empty with (IntMap.empty :: Log ()).

20.05.2013, 15:36, "Nicolas Trangez" <nicolas at incubaid.com>:
> All,
>
> Since I'm stuck on a coding problem and can't figure out how to proceed,
> I decided to call for help.
>
> I'm unable to get some code to typecheck, so maybe I'm missing something
> obvious on the implementation side, or more likely the design is
> completely wrong.
>
> Here's the idea: I have some code which uses some log of "Entry a"
> values (for some polymorphic type 'a'), and provides actions which
> output "Command a" values which should be interpreted by some wrapper
> code, e.g. adding some new entries to the log. These actions are
> implemented in a custom WriterT transformer (in this demo code, the
> original is more complex) to output Commands, while the inner monad
> should give access to the log entries (this could be in-memory like in
> the example, or stored on disk so using IO).
>
> You can find a trimmed-down version at
> https://gist.github.com/NicolasT/4230251f4f87f110d197
>
> This doesn't type-check, and I'm not sure how to proceed. Am I taking a
> wrong approach? Do I need a different design?
>
> Thanks,
>
> Nicolas
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list