Abstract data types / non-indexed columns in IxSet

Data.IxSet

from the library ixset

provides multi-column tables with indexes for each column and computed indexes for nonexistent columns.

How can I put an abstract value into a non-indexed column?

Here's an example. I have a module Lib

that exports a type Abstract

without any constructors, but with some functionality to manipulate opaque values.

module Lib (Abstract, makeAbstract) where
data Abstract = Abstract (Int -> Int)
makeAbstract x = Abstract (\x -> 42 * x + y)

      

I can have a normal map such as Map String Abstract

since the value type is not limited. But I can't have IxSet Table

that like (Map String Abstract, Map Int Abstract)

:

module User where
import Lib

data Table = Table { tKey1 :: String, tKey2 :: Int, tValue :: Abstract }

      

Because I have to provide instance Data Table

. Ideally I would like to have newtype Opaque a = Opaque a

one that has all the required instances for anyone a

without imposing constraints on it and use something like:

data Table = Table { tKey1 :: String, tKey2 :: Int, tValue :: Opaque Abstract }
  deriving (Data, Typable, ...)

      

+3


source to share





All Articles