Lets say I have the following (contrived example) for the function f
:
data T where
T :: (Typeable a, Integral a) => { first :: a, second :: a } -> T
printType :: forall a. Typeable a => String
printType = show $ typeRep (Proxy :: Proxy a)
f :: T -> String
f (T first second) = show (toInteger first, toInteger second)
I can alternatively use record syntax:
f (T {first, second}) = show (toInteger first, toInteger second)
But lets say I wanted to print the type. Then I use a type application:
f (T @a first second) = printType @a ++ ": " ++ show (toInteger first, toInteger second)
But when I put the type application and record syntax together, it fails to compile:
f (T @a {first, second}) = printType @a ++ ": " ++ show (toInteger first, toInteger second)
Is there any way I can use record syntax whilst still also matching on the type? Or alternatively is there a not too ugly syntax hack I can use to work around this?
f (T {first = first :: a, second})
It also doesn't work with the named field pun.