Type Families and defaults

Mitar mmitar at gmail.com
Wed Sep 8 09:38:38 EDT 2010


Hi!

> I'm afraid I didn't understand your questions well enough to answer them.

My question is, why does this type check:

instance Neuron TestNeuron where
  data LiveNeuron TestNeuron = LiveTestNeuron NeuronId

  mkLiveNeuron nid = LiveTestNeuron nid
  getNeuronId (LiveTestNeuron nid) = nid

  live _ _ = return ()

  attach nerve = ((liftM mkLiveNeuron) . forkIO $ bracket (grow :: IO
FooNeuron) dissolve (live nerve)) :: IO (LiveNeuron TestNeuron)

FooNeuron is obviously different to TestNeuron (but both are instances
of Neuron class).

Type signature is:

attach nerve = ((liftM mkLiveNeuron) . forkIO $ bracket (grow :: IO n)
dissolve (live nerve)) :: IO (LiveNeuron n)

This seems different to:

attach nerve = ((liftM mkLiveNeuron) . forkIO $ bracket (grow ::
forall n. IO n) dissolve (live nerve)) :: IO (LiveNeuron n)

which does not type check.

Maybe I am missing some basic understanding.

> But it'd be worth reading http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/other-type-extensions.html#scoped-type-variables

I had. Thanks.


Mitar


More information about the Glasgow-haskell-users mailing list