TL;DR
is their a way I can construct a heterogenous list constrained to some typeclass, without calling a constructor on each element?
I finally have the opportunity to take a deeper dive into Haskell, and I am trying to build a DSL that generates a query string for a SQL like language. The following is pseudo code for what I am trying to attempt, these types will be more refined once I have a better idea of how to approach this. Please excuse the vagueness.
The desired syntax for my dsl is something like
from :: String -> Query
select :: [String] -> Query -> Query
select ["this", "that"] $ from "tbl"
The trouble is that I would also like to allow for things like Column arithmetic and logical operators in the argument to select. For example
(<~) :: String -> Column -> Column -- used for assigning a new name
add :: String -> String -> Column
select ["stuff" <~ "this" `add` "that", "this"] $ from "tbl"
the output of which could be something like
SELECT
this + that as stuff,
this
FROM tbl;
The obvious problem is that this requires a heterogeneous list. I could create a new data type to wrap up these values and go on with my life, but I think the result is much more cumbersome
select ["stuff" <~ (Column "this") `add` (Column "that"), Column "this", Column "that"] $ from "tbl"
I have seen some tricks using GADT's and Existentials but they all require wraping each value in a constructor while I stubbornly want my strings as is. Is it possible??
HList
package has such a thing). This will look pretty, but your error messages will be scary. – dfeuer