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

How to get rid of CoRec after a melt #174

Open
MMesch opened this issue Jun 19, 2023 · 1 comment
Open

How to get rid of CoRec after a melt #174

MMesch opened this issue Jun 19, 2023 · 1 comment

Comments

@MMesch
Copy link

MMesch commented Jun 19, 2023

Hi all,

I'm trying to get rid of the "value" :-> CoRec ElField '[("field1", type1), ("field2", type2)] column in favour of one column called "key" storing the labels and "value" storing the values. The first is quite easy:

type CollapsedFields = '["field1" :-> Int, "field2" :-> Int]
fld :: CoRec ElField CollapsedFields -> String
fld = foldCoRec func
    where
        func :: forall (a :: (Symbol, *)). a ∈ CollapsedFields => ElField a -> String
        func x = case x of
            Field _ -> getLabel x

but the latter is really difficult because GHC somehow needs to know that all fields are Integers—or know what to do if not. This therefore fails:

type CollapsedFields = '["field1" :-> Int, "field2" :-> Int]
fld :: CoRec ElField CollapsedFields -> Int
fld = foldCoRec func
    where
        func :: forall (a :: (Symbol, *)). a ∈ CollapsedFields => ElField a -> Int
        func x = case x of
            Field _ -> getField x

with

• Could not deduce: t ~ Int
  from the context: (a ~ '(s, t), KnownSymbol s)
    bound by a pattern with constructor:
               Field :: forall (s :: Symbol) t.
                        KnownSymbol s =>
                        t -> ElField '(s, t),
             in a case alternative
    at xxxx
  ‘t’ is a rigid type variable bound by
    a pattern with constructor:
      Field :: forall (s :: Symbol) t.
               KnownSymbol s =>
               t -> ElField '(s, t),
    in a case alternative
    at xxxx
  Expected type: ElField '(s, Int)
    Actual type: ElField a
• In the first argument of ‘getField’, namely ‘x’
  In the expression: getField x
  In a case alternative: Field _ -> getField x (typecheck -Wdeferred-type-errors)

The match function that Vinyl provides seems not to work with ElField.

Any ideas how to do this?

@idontgetoutmuch
Copy link

This seems somewhat related: #186

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

2 participants