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

Roman Cheplyaka roma at ro-che.info
Mon Jul 28 07:47:34 UTC 2014


* 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140728/a2b86ad5/attachment.sig>


More information about the Haskell-Cafe mailing list