[Haskell-beginners] How to avoid repeating a type restriction from a data constructor
gs
voldermort at hotmail.com
Wed Apr 24 15:25:01 CEST 2013
Daniel Fischer <daniel.is.fischer <at> googlemail.com> writes:
> I meant example code using a GADT for Source, and not DatatypeContexts; and
> some function where you still need the context.
OK, here are some truncated instances/functions:
data Source v a where
Source :: Variable v => {bindings :: v [Binding a] ,var :: v a} -> Source v a
instance Variable v => Variable (Source v) where
newVar a = do bindings <- newVar []
v <- newVar a
return $ Source bindings v
instance Variable v => Bindable (Source v) where
bind (Source bindings var) extract target apply =
do let binding = Binding extract target apply
--update the new binding
a <- readVar var
data BindingList v a where
BindingList :: Variable v => {source :: Source v a, list :: v [v a],pos
:: v Int} -> BindingList v a
fromBindingList :: Variable v => BindingList v a -> IO [a]
fromBindingList b = do update b
readVar (list b) >>= mapM readVar
instance Variable v => Bindable (BindingList v) where
bind = bind . source
More information about the Beginners
mailing list