Skip to content

Type level Sum/Variant #21

@xal-0

Description

@xal-0

It would be nice to have a "map-like" Sum/Variant type to go along with Data.Type.Map. It could look something like:

data Sum (n :: [Mapping Symbol *]) where
  This :: Var k -> v -> Sum ((k ':-> v) ': m)
  That :: Sum m -> Sum ((k ':-> v) ': m)

I'm using Map right now to build up records by field name (irrespective of field order), and I want to extend it to records with more than one constructor. Sum would be perfect for this, because one could represent:

data A = B { one :: Int, two :: Bool } | C { three :: Char }

as the generic

Sum '[ "B" ':-> Map '[ "one" ':-> Int, "two" ':-> Bool ]
     , "C" ':-> Map '[ "three" ':-> Char ]
     ]

As far as I'm aware, there are packages on hackage that provide generic variant types, but none that provide a generic tagged and sorted variant that's dual to Map. Would it make sense to add this to type-level-sets?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions