-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
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?
Metadata
Metadata
Assignees
Labels
No labels