Skip to content

Instantly share code, notes, and snippets.

@david-christiansen
Created June 22, 2015 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-christiansen/46d9b8dddb41ef98ef6d to your computer and use it in GitHub Desktop.
Save david-christiansen/46d9b8dddb41ef98ef6d to your computer and use it in GitHub Desktop.
data HList : List Type -> Type where
Nil : HList []
(::) : t -> HList ts -> HList (t :: ts)
%name HList xs,ys
append : HList ts -> HList ts' -> HList (ts ++ ts')
append [] ys = ys
append (x :: xs) ys = x :: append xs ys
--------------------------------
data Column = TEXT | REAL | INTEGER
Table : Type
Table = List (String, Column)
interpCol : Column -> Type
interpCol TEXT = String
interpCol REAL = Double
interpCol INTEGER = Integer
interp : Table -> Type
interp schema = HList (map (interpCol . snd) schema)
PeopleSchema : Table
PeopleSchema = [("Name", TEXT), ("Hamsters", INTEGER)]
People : List (interp PeopleSchema)
People = [["David", 1], ["Edwin", 0]]
total
countHamsters : List (interp PeopleSchema) -> Integer
countHamsters [] = 0
countHamsters ([_, h] :: xs) = h + countHamsters xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment