{- |
Copyright : (c) Henning Thielemann 2007
Maintainer : haskell@henning-thielemann.de
Stability : stable
Portability : Haskell 98
Event list with absolute times starting with a time and ending with a body
-}moduleData.EventList.Absolute.TimeTime(T,pause,isPause,viewL,cons,snoc,mapBody,mapTime,mapM,mapM_,mapBodyM,mapTimeM,getTimes,getBodies,duration,merge,mergeBy,insert,insertBy,decreaseStart,delay,filter,partition,slice,foldr,mapMaybe,catMaybes,normalize,isNormalized,collectCoincident,flatten,mapCoincident,append,concat,cycle,discretize,resample,)whereimportData.EventList.Absolute.TimeTimePrivateimportData.EventList.Absolute.TimeBodyPrivate(($~))importqualifiedData.EventList.Absolute.TimeBodyPrivateasTimeBodyPrivimportqualifiedData.EventList.Absolute.TimeBodyasTimeBodyListimportqualifiedData.AlternatingList.List.DisparateasDispimportqualifiedData.AlternatingList.List.UniformasUniformimportqualifiedData.AlternatingList.List.MixedasMixedimportqualifiedData.ListasListimportqualifiedData.EventList.UtilityasUtilityimportData.EventList.Utility(mapPair,mapSnd,toMaybe,isMonotonic)importqualifiedControl.MonadasMonadimportControl.Monad.State(State(State),evalState)importData.Maybe(fromMaybe)importPreludehiding(null,foldr,map,filter,concat,cycle,sequence,sequence_,mapM,mapM_)pause::time->Ttimebodypause=Cons.Uniform.singletonisPause::Ttimebody->BoolisPause=Uniform.isSingleton.deconsgetBodies::Ttimebody->[body]getBodies=Uniform.getFirsts.deconsgetTimes::Ttimebody->[time]getTimes=Uniform.getSeconds.deconsduration::Numtime=>Ttimebody->timeduration=snd.viewTimeR-- duration = last . getTimescons::time->body->Ttimebody->Ttimebodyconstimebody=lift(Uniform.constimebody)snoc::Ttimebody->body->time->Ttimebodysnocxsbodytime=Cons$(Uniform.snoc$*xs)bodytimeviewL::Ttimebody->(time,Maybe(body,Ttimebody))viewL=mapSnd(fmap(mapSndCons).Mixed.viewFirstL).Mixed.viewSecondL.deconsmapBody::(body0->body1)->Ttimebody0->Ttimebody1mapBody=lift.Uniform.mapFirstmapTime::(time0->time1)->Ttime0body->Ttime1bodymapTime=lift.Uniform.mapSecondmapM::Monadm=>(time0->mtime1)->(body0->mbody1)->Ttime0body0->m(Ttime1body1)mapMfg=liftM(Uniform.mapMgf)mapM_::Monadm=>(time->m())->(body->m())->Ttimebody->m()mapM_fg=Uniform.mapM_gf.deconsmapBodyM::Monadm=>(body0->mbody1)->Ttimebody0->m(Ttimebody1)mapBodyM=liftM.Uniform.mapFirstMmapTimeM::Monadm=>(time0->mtime1)->Ttime0body->m(Ttime1body)mapTimeM=liftM.Uniform.mapSecondMfoldr::(time->a->b)->(body->b->a)->a->Ttimebody->bfoldrfgx=Uniform.foldrgfx.deconsfilter::(Numtime)=>(body->Bool)->Ttimebody->Ttimebodyfilterp=mapMaybe(\b->toMaybe(pb)b)mapMaybe::(Numtime)=>(body0->Maybebody1)->Ttimebody0->Ttimebody1mapMaybef=catMaybes.mapBodyfcatMaybes::(Numtime)=>Ttime(Maybebody)->TtimebodycatMaybes=mapTimeInitTimeBodyList.catMaybes{-
Could be implemented more easily in terms of Uniform.partition
-}partition::(body->Bool)->Ttimebody->(Ttimebody,Ttimebody)partitionp=(\(xs,t)->mapPair(flipsnocTimet,flipsnocTimet)(TimeBodyList.partitionpxs)).viewTimeRslice::(Eqa,Numtime)=>(body->a)->Ttimebody->[(a,Ttimebody)]slice=Utility.slice(fmapfst.snd.viewL)partitioncollectCoincident::Eqtime=>Ttimebody->Ttime[body]collectCoincident=Cons.(uncurry$\t0->Mixed.consSecondt0.Mixed.mapFirstInit(Uniform.catMaybesFirst.flipevalState(Justt0).Uniform.mapFirstM(\time->State$\oldTime->(Monad.guard(time/=oldTime)>>time,time)).Uniform.mapFirstJust)).Mixed.viewSecondL.deconsflatten::(Ordtime,Numtime)=>Ttime[body]->Ttimebodyflatten=mapTimeInitTimeBodyList.flatten{- |
Apply a function to the lists of coincident events.
-}mapCoincident::(Ordtime,Numtime)=>([a]->[b])->Ttimea->TtimebmapCoincidentf=flatten.mapBodyf.collectCoincident{- |
'List.sort' sorts a list of coinciding events,
that is all events but the first one have time difference 0.
'normalize' sorts all coinciding events in a list
thus yielding a canonical representation of a time ordered list.
-}normalize::(Ordtime,Numtime,Ordbody)=>Ttimebody->Ttimebodynormalize=mapCoincidentList.sortisNormalized::(Ordtime,Numtime,Ordbody)=>Ttimebody->BoolisNormalized=allisMonotonic.getBodies.collectCoincidentmerge::(Ordtime,Ordbody)=>Ttimebody->Ttimebody->Ttimebodymerge=mergeBy(<)mergeBy::(Ordtime)=>(body->body->Bool)->Ttimebody->Ttimebody->TtimebodymergeBybeforexs0ys0=let(xs,xt)=viewTimeRxs0(ys,yt)=viewTimeRys0insnocTime(TimeBodyList.mergeBybeforexsys)(maxxtyt)insert::(Ordtime,Ordbody)=>time->body->Ttimebody->Ttimebodyinsert=insertBy(<)insertBy::(Ordtime)=>(body->body->Bool)->time->body->Ttimebody->TtimebodyinsertBybeforet0me0mevs1=letmev0=(t0,me0)(t1,mxs)=viewLmevs1inmaybe(uncurryconsmev0$pause(maxt0t1))(\(ev1,mevs)->letmev1=(t1,ev1)inifUtility.beforeBybeforemev0mev1thenuncurryconsmev0$mevs1elseuncurryconsmev1$uncurry(insertBybefore)mev0mevs)mxsappend::(Ordtime,Numtime)=>Ttimebody->Ttimebody->Ttimebodyappend=(\(xs,t)->lift(Mixed.appendDisparateUniform$~xs).delayt).viewTimeRconcat::(Ordtime,Numtime)=>[Ttimebody]->Ttimebodyconcatxs=letts0=scanl(+)0(List.mapdurationxs)(ts,dur)=fromMaybe(error"list of accumulated times is always non-empty")(Utility.viewRts0)insnocTime(TimeBodyPriv.Cons$Disp.concat$List.mapTimeBodyPriv.decons$zipWithTimeBodyList.delayts(List.map(fst.viewTimeR)xs))durcycle::(Ordtime,Numtime)=>Ttimebody->Ttimebodycycle=concat.List.repeatdecreaseStart::(Ordtime,Numtime)=>time->Ttimebody->TtimebodydecreaseStartdif=Cons.(\(t,xs)->Mixed.consSecond(ift>=difthent-difelseerror"decreaseStart: difference too big")(Disp.mapSecond(subtractdif)xs)).Mixed.viewSecondL.deconsdelay::(Ordtime,Numtime)=>time->Ttimebody->Ttimebodydelaydif=ifdif>=0thenmapTime(dif+)elseerror"delay: negative delay"discretize::(RealFractime,Integrali)=>Ttimebody->Tibodydiscretize=mapTimeroundresample::(RealFractime,Integrali)=>time->Ttimebody->Tibodyresamplerate=discretize.mapTime(rate*)