-
Notifications
You must be signed in to change notification settings - Fork 18
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
Case struct #7
Case struct #7
Conversation
Hey looks nice! Out of curiosity, what is the benefit of representing variants as singleton records? Note that you can also extract the key and type directly from a record, something like this: class RowSingleton label typ row | row -> label typ
instance rowSingleton :: (R.RowToList row (R.Cons label typ (R.Nil))) => RowSingleton label typ row (uhm the fundeps probably could be made bidirectional with ListToRow ... idk) I was also thinking maybe [edit] Also, keeping the other functions is a really good idea since they support polymorphism with constraints (and typeclass dictionaries) in ways can't happen with records, where the constraints can't be solved and the variants lose the dictionaries and such. The only reason P.S. No worries I've done that before. Also, I don't really know what I'm doing so having something to compare against is good! |
@MonoidMusician Uhm, I just think that we actually have a way of representing foo = inj (SProxy :: SProxy "foo") foo
foo = variant { foo: foo } You mean you need something like this for constraints, right cases2 ∷ ∀ a. Show a ⇒ { quux ∷ a → String }
cases2 = { quux: ("tst" <> _ ) <<< show }
quux ∷ ∀ a r. Show a ⇒ a → Variant (quux ∷ a|r)
quux a = downcast $ variant { quux: a } so for large case :: forall a b c d. Show a => Show b => Show c => Show d => { ... } Looks like compiler is smart enough to union them and handle type constraints { quux: ("tst" <> _ ) <<< show } :+: { trololo: \a → eq a a } Autotype is forall t17 t20.
Show t17 => Eq t20 => { trololo :: t20 -> Boolean
, quux :: t17 -> String
} |
sigh, complex issue, here goes ... yeah, it sometimes works ... it surprised me that but it won't work when the nor will it work when not all of the type variables are constrained by the Variant's row, so open rows will probably not work – which was the default in the tests ( and it still won't unify so you're right, it works in more cases than I expected! but it's still rather fragile. |
Closing this in favour of #6. @MonoidMusician would you mind adding |
O(1)
matchSProxy :: SProxy "blablabla"
I don't think that removing
on|case_|default
is good idea, callbacks might be a bit simpler to understand.@natefaubion How does this approach look? If you like it, I'll add same thing for
Data.Functor.Variant