Thanks to the answer to this question I've defined a type like so:
data Chain = forall a. Integral a => Chain [[a]] [a] a a
I need to write a getter function for each field, or argument if you like. Here's my first attempt:
getSimplices (Chain simplices _ _ _) = simplices
But when I try to compile ghc gives the following error:
Chain.hs:10:40: error:
• Couldn't match expected type ‘t’ with actual type ‘[[a]]’
because type variable ‘a’ would escape its scope
This (rigid, skolem) type variable is bound by
a pattern with constructor:
Chain :: forall a. Integral a => [[a]] -> [a] -> a -> a -> Chain,
in an equation for ‘getSimplices’
at Chain.hs:10:15-35
• In the expression: simplices
In an equation for ‘getSimplices’:
getSimplices (Chain simplices _ _ _) = simplices
• Relevant bindings include
simplices :: [[a]] (bound at Chain.hs:10:21)
getSimplices :: Chain -> t (bound at Chain.hs:10:1)
I fixed it like this:
getSimplices (Chain simplices _ _ _) = map (map fromIntegral) simplices
Even if some kind of ghc magic prevents this from being obscenely slow for a getter, I think fixing something this way is just atrocious. Is there a better way to define getters for types like this?