Say I have a set of records, as in
data A = A { a:: String } deriving (Show)
data B = B { b:: String } deriving (Show)
Then some type class
class Foo a where
foo :: a -> IO ()
instance Foo A where
foo c = ...
And I also want to do something like
bar = do
push (A {a="x"})
push (B {b="y"})
And have these things end up in a list l somewhere to be run at a later time, such that I can
map foo l
Should I write template haskell to generate a wrapper type and derive instances so the list can be of the wrapper type? Is there a more intelligent way to go about this? I’m honestly feeling pretty pinned down by the haskell type system, and know there has to be a better way to do this.
There are ways to do this with existential quantification, but it’s often overkill. A more Haskell-y approach would be to simply apply
fooup front and keep a[IO ()]list of the resulting actions, which you can thensequencelater to run them.