module Reactive.Updatable where
import Reactive.Input
type UpdateData d iv = (d->d, InQList d iv -> InQList d iv)
class Updatable p d iv where
update :: UpdateData d iv -> p -> p
instance Updatable (InQList d iv) d iv where
update (f,nq) (InQList al (IDQ d q)) = InQList (fmap (\(d1,v1) -> (f d1,v1)) al) (IDQ (f d) $ update (f,nq) q)
update (_,_) InQEnd = InQEnd
update (_,nq) InQUndef = nq InQUndef
instance Updatable Integer d iv where
update _ = id
instance Updatable Bool d iv where
update _ = id
instance Updatable Int d iv where
update _ = id
instance Updatable Rational d iv where
update _ = id
instance Updatable Char d iv where
update _ = id
instance Updatable () d iv where
update _ = id
instance Updatable p d iv => Updatable (Maybe p) d iv where
update _ Nothing = Nothing
update u (Just p) = Just (update u p)
instance Updatable p d iv => Updatable [p] d iv where
update u l = map (update u) l
instance (Updatable p1 d iv, Updatable p2 d iv) => Updatable (p1,p2) d iv where
update u (p1,p2) = (update u p1, update u p2)
instance (Updatable p1 d iv, Updatable p2 d iv, Updatable p3 d iv) => Updatable (p1,p2,p3) d iv where
update u (p1,p2,p3) = (update u p1, update u p2,update u p3)
instance (Updatable p1 d iv, Updatable p2 d iv, Updatable p3 d iv, Updatable p4 d iv) => Updatable (p1,p2,p3,p4) d iv where
update u (p1,p2,p3,p4) = (update u p1, update u p2, update u p3, update u p4)
instance (Updatable p1 d iv, Updatable p2 d iv) => Updatable (Either p1 p2) d iv where
update u (Left p1) = Left (update u p1)
update u (Right p2) = Right (update u p2)
instance Updatable p d iv => Updatable (p -> q) d iv where
update u f = f