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
generic-programming haskell abstract-data-type


source to share


No one has answered this question yet

Check out similar questions:

305
How to use lists correctly in R?
67
What are the problems with the ADT encoding that associates types with data constructors? (For example, Scala.)
32
What is ADT? (Abstract data type)
fourteen
Lists in Haskell: data type or abstract data type?
3
data abstraction type comp
3
What is the name of this abstract data type?
3
A good way to map a key to a generic type in C ++?
3
Abstract data types in class class definition
3
Abstract data types versus parametric polymorphism in Haskell
0
Abstract data types



All Articles
Loading...
X
Show
Funny
Dev
Pics