[Haskell-beginners] problems with GADTs

Michael Litchard michael at schmong.org
Wed Sep 1 15:05:41 EDT 2010

I'm learnined how to use GADTs, but for the moment I'm stuck on the
following problem.

some context first

> newtype Cost = Cost Int
> newtype ID = ID Int
> newtype Student = Student String
> newtype Activity = Activity String
> data Table k v = PopTable
>       { tableName :: String
>       , tableList :: [(k, v)]
>       } deriving (Show, Read)
> type Students = Table ID Student
> type ActivityCosts = Table Activity Cost
> type StudentActivities = Table Activity ID

I want to do something like this

> loaders = [("students", loadStudentIDs), ("costs", loadActivityCosts), ("activities", loadStudentActivities)]

But I can't have list with multiple types. Okay so ski (from #haskell)
suggested I use a GADT. This is new territory for me. Here's what it
looks like right now.

data ProgramName :: * -> *
     PNStudents :: ProgramName Students
     PNCosts    :: ProgramName ActivityCosts
     PNActivities :: ProgramName StudentActivities

Now I should be able to use this to define a data structure called
"loaders" that contains three tuples ("students", loadStudentIDs),
("costs", loadActivityCosts), and ("activities",

So, what would "loaders" look like? I've done some reading but it's
not sunk in yet.

More information about the Beginners mailing list