I have a scenario that involves type classes and I'm not quite sure how to go about solving it.
I have
class Event a where
timestamp :: a -> UTCTime
rawData :: a -> ByteString
class Something a where
something :: a -> SomethingElse
In my code, I want to create an object that implements both Event and Something. However, in certain cases, the function something is going to need the return from a call to rawData to construct the SomethingElse object. I was wondering if there was to structure these type classes to be able to build a function like
convert :: (Event a, Event b, Something b) => a -> b
being able to call convert x :: (Instance of something) in order to convert, a bit like how binary get is used.
I realize that this is a rather vague description, but please let me know if I can add anything else.
Thanks
convertto be able to return a value of anyEvent&Somethingtype, you need a way to construct a value of anyEvent&Somethingtype while knowing only that the type belongs to those two classes. You could give one of the classes a method likeunraw :: ByteString -> aor, if such a method would require utilizing features of both classes for some reason, make a new class that inherits bothEvent&Somethingand has the desired constructor.SomethingElse, way not justByteString?