haskell - Exporting a polymorphic MonadState function for a particular state data type -
what i'm trying (in module i'm writing) export function works on particular type in state monad (in example below, type foo). user able use function in whatever monadstate type wish: state.lazy, state.strict, statet, etc. needs polymorphic in outer state monad.
here example of i'd do:
edited better question:
import control.monad.state data foo = foo { cnt :: int, val :: } --test :: state (foo a) -- works --test :: statet (foo a) maybe -- ...so -- ... including following signature gives error: test :: monadstate (foo a) m => m test = modify (\(foo a)-> foo (i+1) a) >> gets val ghc complains flexibleinstances extension required define type above. using extension correct way define function or there better way?
thanks
can't use monadstate typeclass?
{-# language flexiblecontexts #-} import control.monad.state data foo = foo { cnt :: int, val :: } test :: monadstate (foo a) m => m test = modify (\(foo a)-> foo (i+1) a) >> gets val it loads fine in ghci.
edit: mtl-2.0 , ghci-7.0.1
Comments
Post a Comment