Is it possible to have a type be part of a typeclass? Something like:
class KeyTraits v where
keyType :: *
key :: v -> keyType
data TableRow = { date :: Date, metaData :: String, value :: Int }
instance KeyTraits TableRow where
keyType = Date
key = date
And can these "type-level" functions be used elsewhere? For example:
-- automatically deduce the type for the key, from the value type, using
-- the typeclass
data MyMap v = { getMap :: (KeyTraits v) => Map (keyType) v }
I may be doing something completely wrong, but I basically want the ability to define type relationships like the one above (e.g. Certain values already may have data that can be used as a Key). If that's not possible, or is difficult, could you suggest a better design that is more idiomatic?
Thank you!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With