0

I want to use the postgresql-simple library to construct a Map or HashMap of SqlValues. I know one approach to do this would be to redefine all of the SqlValue's into a single universal type ala

data SqlValue = SqlInt Int
              | SqlString String
              | SqlJson Value
              etc

But I am wondering if there is a more effective way of doing this where I can create a map that allows it's value's to be any type that implement's the FromField class.

Is it possible to at the least reduce the amount of overhead associated with it by using TypeFamilies or something similar where I can take make each instance of the type also require an instance of FromField

The end goal is to have postgresql-simple produce something along the lines of the following:

[Map SqlColumnName SqlValue]
emg184
  • 850
  • 8
  • 19
  • Actually, your **end goal** is probably to use the resulting `Map SqlColumnName SqlValue` in a program. This is an important consideration (usually the most important consideration and the one everyone forgets to consider) when contemplating heterogeneous data structures in Haskell. So, can you give an example of what you'd like to do with the resulting map? – K. A. Buhr Nov 25 '20 at 17:34
  • What you asked for would be `{-# LANGUAGE ExistentialQuantification #-} data SqlValue = forall t. FromField t => SqlValue t`, but that's almost certainly not what you actually *want*. – Joseph Sible-Reinstate Monica Nov 25 '20 at 22:09

0 Answers0