type-level-sets
type-level-sets copied to clipboard
Add functional dependency to IsMember for better type inference
Resolves #26
Added another commit for better inference with update
. Previously,
ghci> m = Ext (Var @"z") 'b' $ Ext (Var @"w") 'a' Empty
ghci> m
{z :-> 'b', w :-> 'a'}
ghci> update m (Var @"w") 3
• Could not deduce (Updatable
"w" t0 '[ "z" ':-> Char, "w" ':-> Char] n)
from the context: (Updatable
"w" t '[ "z" ':-> Char, "w" ':-> Char] n,
Num t)
bound by the inferred type for ‘it’:
forall t (n :: [Mapping Symbol *]).
(Updatable "w" t '[ "z" ':-> Char, "w" ':-> Char] n, Num t) =>
Map n
at <interactive>:973:1-26
The type variable ‘t0’ is ambiguous
• In the ambiguity check for the inferred type for ‘it’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
When checking the inferred type
it :: forall t (n :: [Mapping Symbol *]).
(Updatable "w" t '[ "z" ':-> Char, "w" ':-> Char] n, Num t) =>
Map n
ghci> update m (Var ::Var "w") (3::Int)
update m (Var ::Var "w") (3::Int)
:: Updatable "w" Int '[ "z" ':-> Char, "w" ':-> Char] n => Map n
With 686f64d,
ghci> m = Ext (Var @"z") 'b' $ Ext (Var @"w") 'a' Empty
ghci> m
{z :-> 'b', w :-> 'a'}
ghci> update m (Var @"w") 3
{z :-> 'b', w :-> 3}
ghci> :t update m (Var @"w") 3
update m (Var @"w") 3 :: Num t => Map '[ "z" ':-> Char, "w" ':-> t]
Actually, never mind the update thing. I consider it better, but it changes the number of parameters to the Updatable
class, which is a breaking change that shouldn't be included in this PR. Let me know if you'd like me to open a separate PR with that.
Ping @dorchard
This change is very useful in some stuff I'm building on top of type-level-sets
. Thank you, @jmorag!