[Haskell-beginners] How to avoid repeating a type restriction from a data constructor
gs
voldermort at hotmail.com
Wed Apr 24 20:34:07 CEST 2013
Daniel Fischer <daniel.is.fischer <at> googlemail.com> writes:
> No, that is the catch:
>
> undefined :: Source NotAnInstanceOfVariable Int
>
> is possible.
OK, I've got that. Now let's say that
data Source v a = Variable v => Source {bindings :: v [Binding a], var :: v a}
or
data Variable v => Source v a = Source {bindings :: v [Binding a], var :: v a}
instance Variable (Source v) where
newVar a = do bindings <- newVar []
v <- newVar a
return $ Source bindings v
was allowed - then newVar (undefined :: Source NotAnInstanceOfVariable Int)
would then attempt newVar (?? :: NotAnInstanceOfVariable), which doesn't
type check, because newVar only works on Variables.
Is this correct? If that's the only problem, it doesn't seem like much of a
loss, as even with the type context, undefined :: Source
SomeInstanceOfVariable Int isn't going to be of much use either.
More information about the Beginners
mailing list