Type Families and defaults
simonpj at microsoft.com
Thu Sep 9 05:46:51 EDT 2010
| > I'm afraid I didn't understand your questions well enough to answer them.
| My question is, why does this type check:
It's hard for me to answer a question like that! To explain why something type checks I'd have to show every constraint and how it is solved.
I think you have something more specific in mind. Maybe you think "this should not typecheck". E.g. here's an expression (f x), and f has type Int -> <blah, and x has type Boo, so the application should fail to typecheck.
You say that example 1 (which typechecks) is different to example 2 (which does not). Again, in itself that's not surprising. They differ, so their behaviours may differ.
Do remember that (e :: IO n)
means (e :: forall n. IO n)
unless you have ScopedTypeVariables
Sorry not to be more helpful.
| 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
| I had. Thanks.
More information about the Glasgow-haskell-users