[Haskell-beginners] abstracting parametrized record types
Alia
alia_khouri at yahoo.com
Thu Oct 2 19:34:18 UTC 2014
Hi Folks,
Here's a problem that's frustrating me:
I have defined a parametrized record type which looks like this:
data Job a = Job
{ jobID :: String
, jobName :: String
, jobTable :: String
, jobSource :: IO [a]
, jobProcessors :: [a -> a]
}
where a is a data model type that maps on to a database table, for example:
data Person = Person
{ name :: String
, age :: Int
} deriving (Show)
data Car = Car
{ brand :: String
, value :: Double
, year :: Int
} deriving (Show)
I would like to define a higher-level record type which contains,
for configuration purposes, a certain set of jobs for execution. Let's
say we call it a JobSet and which could possibly look like this:
data JobSet = JobSet
{ jobsetID :: String
, jobsetName :: String
, jobs :: [Job] <-- yes I know this is not legal
}
Is there a legal haskell way to achieve the above objective without
having to do something like this which hardcodes the model type into the
jobset schema?
data JobSet = JobSet
{ jobsetID :: String
, jobsetName :: String
, personJobs :: [Job Person]
, carJobs :: [Job Car]
}
Many thanks for any enlightenment on this front.
Alia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20141002/08bbe562/attachment.html>
More information about the Beginners
mailing list