Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type level Sum/Variant #21

Open
xal-0 opened this issue May 23, 2019 · 0 comments
Open

Type level Sum/Variant #21

xal-0 opened this issue May 23, 2019 · 0 comments

Comments

@xal-0
Copy link

xal-0 commented May 23, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant