[Haskell-beginners] What should be inside the Monad or MonadTrans's type declaration? --Bound library question2.

Anthony Lee anthonynlee at gmail.com
Sun Aug 19 20:31:57 UTC 2018


Hi,
In Scope.hs there is one instance of Monad and one instance of MonadTrans
for Scope,
For the Monad instance, it is defined like this: Monad (Scope b f);
For the MonadTrans instance, it is like this: MonadTrans (Scope b);
Does it mean:
 In ">>=" the e represents  (a)  of (Scope b f a)?
 In lift function the m represents (f a) of (Scope b f a)?

https://github.com/ekmett/bound/blob/master/src/Bound/Scope.hs
========================Scope.hs================================
instance Monad f => Monad (Scope b f) where
#if !MIN_VERSION_base(4,8,0)
  return a = Scope (return (F (return a)))
  {-# INLINE return #-}
#endif
  Scope e >>= f = Scope $ e >>= \v -> case v of
    B b -> return (B b)
    F ea -> ea >>= unscope . f
  {-# INLINE (>>=) #-}

instance MonadTrans (Scope b) where
  lift m = Scope (return (F m))
  {-# INLINE lift #-}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180819/c8fdfb22/attachment.html>


More information about the Beginners mailing list