i am not quite sure how to do this in the most elegant way:
I have some data structures:
data A = A Double
data B = B Double
data C = C Double
...
and i want to allow only a subset in another data structure, so i did something like this:
data SubSet = SubSetA A | SubSetC C
and use it in Foo:
data Foo = Foo [SubSet]
No i want to perform a polymorphic operation on the contents of A,B,C, e.g.
doSomething :: Foo -> [Double]
doSomething (Foo s) = map doSomethingElse s
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS -fglasgow-exts #-}
import Generics.EMGM
import Generics.EMGM.Derive
data A = A Double
data B = B Double
data C = C Double
data Subset = SubsetA A | SubsetC C
data Foo = Foo [Subset]
$(deriveMany [''A,''B,''C,''Subset,''Foo])
doSomething :: Foo -> [Double]
doSomething = collect