-
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
Work on mapping variant cases #37
Work on mapping variant cases #37
Conversation
Okay, I added an extensible version ( Just need better names and docs. 😁 |
Thank you for working on this. I haven't reviewed everything in detail, but I have a couple of API thoughts. The type of case_
# over _foo (\a -> show a)
# over _bar (\a -> a + 1)
case_ # overMatch
{ foo: \a -> show a
, bar: \a -> a + 1
}
expand
# over _foo ...
# over _bar ...
expand # overMatch ... |
I'm not super concerned about catering to the |
I'm revisiting this PR since I'm looking at Here's an example usage that I think is important to keep clean: |
Also remove redundant variable `r4` and the corresponding constraint
src/Data/Variant.purs
Outdated
traverse | ||
∷ ∀ r rl ri ro r1 r2 r3 m | ||
. RL.RowToList r rl | ||
⇒ VariantTravCases m rl ri ro |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a small nit, but I think the library tends to use full names where possible, so I'd consider renaming this to VariantTraverseCases
src/Data/Functor/Variant.purs
Outdated
coerceR = unsafeCoerce | ||
|
||
-- | Traverse over some labels (with access to the containers) and use | ||
-- | `travers f` for the rest (just changing the index type). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- | `travers f` for the rest (just changing the index type). | |
-- | `traverse f` for the rest (just changing the index type). |
src/Data/Variant.purs
Outdated
@@ -28,8 +34,8 @@ import Data.Enum (class Enum, pred, succ, class BoundedEnum, Cardinality(..), fr | |||
import Data.List as L | |||
import Data.Maybe (Maybe) | |||
import Data.Symbol (class IsSymbol, reflectSymbol) | |||
import Data.Variant.Internal (class Contractable, class VariantMatchCases) as Exports | |||
import Data.Variant.Internal (class Contractable, class VariantMatchCases, class VariantTags, BoundedDict, BoundedEnumDict, VariantCase, VariantRep(..), contractWith, lookup, lookupCardinality, lookupEq, lookupFirst, lookupFromEnum, lookupLast, lookupOrd, lookupPred, lookupSucc, lookupToEnum, unsafeGet, unsafeHas, variantTags) | |||
import Data.Variant.Internal (class Contractable, class VariantMapCases, class VariantMatchCases) as Exports |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also re-export VariantTraverseCases
?
I'm still looking through the constraints here, but I have reason to use |
My usage of |
I think if y'all are both satisfied with with the implementation/constraints and documentation, then I'm fine with y'all moving forward. I don't currently have any other constructive feedback. |
Other than my naming and import comments I've mentioned above, this looks perfectly good to me. |
@natefaubion I'm happy with the current state of things. |
Release away! |
Fixes #36.
This is a work-in progress. In particular, I don't know of a way to come up with the correct
map
function for theVariantF
that is generated frommapSome
. Will we have to collectmap
dictionaries (corresponding toro
row), and then search for it in there?Note:
mapAll
has a different implementation frommapSome
only because the compiler doesn't solveUnion r () r
, and it is a constraint I don't want to propagate to the user. Otherwise it would bemapAll r = mapSome r case_
.Also need to write tests. All in good time 😉