haskell - Monad Transformers lift -


i looking monad transformers in real world haskell. book said make monad transformer, need make instance of monadtrans type class.

so book defined new transformer, maybet m a transformer.

they defined monadtrans type class new transformer:

instance monadtrans maybet   lift m = maybet (just `liftm` m) 

then made instance of monadstate transformer:

instance (monadstate s m) => monadstate s (maybet m)   = lift   put k = lift (put k) 

from understand lift function taking underlying monad , wrapping in right constructor. however, not implementation of or put in monadstate type class, in understanding lift doing here. have heard in mtl package because of how type classes defined, can have stack of monad transformers writert, statet etc can use functions get,put,tell etc without doing lifting. wondering how work, suspect these type classes not sure?

but can use functions get,put,tell etc without doing lifting

this because functions defined on e.g. monadstate typeclass, not state type.

class monad m => monadstate s m | m -> s     :: m s     put :: s -> m () 

then, both state , statet made instance of class, makes using possible1

in example instance, if know inner monad of maybet m (fulfills) monadstate s, can treat whole outer monad monadstate s provided lift operations directed inner monad fit outer one, done lift.

in plain english, sound "if maybet transformer transforms (wraps) on monad m stateful (monadstate) monad type s, resulting type stateful monad type".


1this 1 instance, because state s a implemented statet s identity a. refer sources implementation details.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -