[Haskell-beginners] Need help to write join on my Temporals
martin
martin.drautzburg at web.de
Fri Apr 10 17:02:13 UTC 2015
Hello all,
I have these Types
type Time = Integer
data Change a = Chg {
ct :: Time, -- "change time"
cv :: a -- "change value"
} deriving (Eq,Show)
data Temporal a = Temporal {
td :: a, -- "temporal default"
tc :: [Change a] -- "temporal changes"
} deriving (Eq, Show)
And I am trying to make Temporal a Monad by implementing join. My first Attempt was awfully verbose. It was also faulty,
which was revealed by this QuickQueck (I am happy with my implementation of <*>)
prop_tJoin tpr1 tpr2 = let f = (*)
y1 = f <$> tpr1 <*> tpr2
y2 = (f <$> tpr1) `ap` tpr2
in y1 == y2
While I understand why my first implementatin was faulty, I fail to come up with anything remotely readable. I don't
understand why I am having such difficulties, let alone solve them. I feel I am approaching this from the wrong angle.
Any advice would be very much appreciated.
More information about the Beginners
mailing list