[Haskell-cafe] forcing a type constraint on data

Mathijs Kwik bluescreen303 at gmail.com
Sun Jan 2 01:37:24 CET 2011

Hi all,

I would like to make a more restrictive version of a certain datatype.
I tried wrapping it in a newtype, fundeps, type families, really got lost :)

What I'm trying to achieve is the following:
The original package
has a constructor function (mkReactor) with exactly the constraints
I'm after. However, the constraint is just on this constructor
function, not on the data itself.
All functions I write are inferred as "Reactor (State s) c", while the
use of that constructor ensures that s == c.
Also, I might switch "State s" for some "StateT s m" later on, so I
would really like to be able to use "(MonadState c m) => Reactor m c"
in my functions as well, since this is the most generic.

Trying that blows up however:
    Could not deduce (m ~ StateT s Identity)
      from the context (ValidEvent event, MonadState s m)
      `m' is a rigid type variable bound by
          the type signature for `stepper2' at Eventer.hs:77:45
    In the first argument of `runState', namely
      `(insertExternals reactor [Serial event])'
    In the expression:
      runState (insertExternals reactor [Serial event]) state
    In an equation for `stepper2':
        stepper2 (Just reactor, state) event
          = runState (insertExternals reactor [Serial event]) state

Can someone please explain the cause of this problem?
Are there workarounds? Language extensions?

Thanks in advance,

More information about the Haskell-Cafe mailing list