[Haskell-cafe] Problem with existential type and instance.

Magicloud Magiclouds magicloud.magiclouds at gmail.com
Mon Jul 28 08:13:40 UTC 2014


I think that is what I need. Thanks.


On Mon, Jul 28, 2014 at 4:04 PM, Roman Cheplyaka <roma at ro-che.info> wrote:

> What do you mean? MonadIO m is a constraint. You have to supply some type
> that
> satisfies this constraint. IO is one such type; you could use any other.
>
> Alternatively, if you *don't* want to store a MonadIO dictionary in the
> Nothing
> case, create your own Maybe type:
>
>   data MaybeMonadIO
>     = NoMonadIO
>     | forall m . MonadIO m => JustMonadIO (m ())
>
>   newtype EventHandlers = EventHandlers { onDeleteWindow :: MaybeMonadIO }
>
> * Magicloud Magiclouds <magicloud.magiclouds at gmail.com> [2014-07-28
> 15:50:05+0800]
> > I see. Thank you.
> >
> > Any anyway I could use (MonadIO m) here, in Nothing data type?
> >
> >
> > On Mon, Jul 28, 2014 at 3:47 PM, Roman Cheplyaka <roma at ro-che.info>
> wrote:
> >
> > > * Magicloud Magiclouds <magicloud.magiclouds at gmail.com> [2014-07-28
> > > 13:46:53+0800]
> > > > Hi,
> > > >
> > > >   For code like below, how to make it compilable?
> > > >
> > > > data EventHandlers = forall m. MonadIO m => EventHandlers {
> > > onDeleteWindow
> > > > :: Maybe (m ()) }
> > > > instance Default EventHandlers where
> > > >   def = EventHandlers Nothing
> > >
> > > GHC has to store some MonadIO dictionary in the existential type, but
> it
> > > cannot
> > > figure out which dictionary to store (it can be any).
> > >
> > > You can tell it which one to use by supplying a type annotation, e.g.:
> > >
> > >   def = EventHandlers (Nothing :: Maybe (IO ()))
> > >
> > > Roman
> > >
> >
> >
> >
> > --
> > 竹密岂妨流水过
> > 山高哪阻野云飞
> >
> > And for G+, please use magiclouds#gmail.com.
>



-- 
竹密岂妨流水过
山高哪阻野云飞

And for G+, please use magiclouds#gmail.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140728/2a5adec5/attachment.html>


More information about the Haskell-Cafe mailing list