[Haskell-cafe] Semantics of temporal data
martin
martin.drautzburg at web.de
Mon Mar 30 20:23:17 UTC 2015
Hello all,
I wrote a Temporal datatype
data Temporal a = Temporal {
td :: a, -- "temporal default"
tc :: [Change a] -- "temporal changes"
} deriving (Eq, Show)
data Change a = Chg {
ct :: Time, -- "change time"
cv :: a -- "change value"
} deriving (Eq,Show)
I got into semantic trouble when trying to write "join" for Temporal (Temporal a).
If I have a Temporal Temporal, then each change's value is a Temporal. The question is: what significance does the
temporal default have? In my implementation, when I look at this
Chg t0 (Temporal default0 changes0)
Chg t1 (Temporal default1 changes1) --<-- you are here
Chg t2 (Temporal default2 changes2)
I accept the changes1 which are >= t1 and less than t2. So far so good. But I also take the default1 and prepend it to
the resuling list of changes with a change time of t1 (unless the first of the changes1 occurs also at t1).
But by comparing results with a handwritten <*>, QuickCheck revealed that this is not in line with
<*> = ap
x >>= f = join $ fmap f x
It appears to me that the defaults of the inner Temporal lose most of their meaning. The effective default is the change
value of the last accepted change from the previous (t0) iteration.
This would make some sense. If I have a summer schedule which lists the location of a single train over time, and it
sais it is usually "nowhere", but at July 1st is shall be in Manchester. If I ask this schedule, where the train will be
before July 1st it'll say "nowhere".
Now if I prepend the summer schedule with a spring schedule, then there will be a last location of that train in the
spring schedule (say Brighton), i.e. before the summer schedule becomes effective. Hence at the beginning of the summer,
the train won't be "nowhere" but in Brighton.
Does this make some sense? Please feel free to comment.
BTW: I am really impressed that haskell pointed out this semantic issue to me. This could have gone unnoticed for months
in other languages.
More information about the Haskell-Cafe
mailing list