-
Notifications
You must be signed in to change notification settings - Fork 2
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
Transform patterns within a subscope #9
Comments
In the comment, I was careful that the second appearance of the variable was in an expression context, not in a pattern context; if both uses are in a pattern, the TH won't have the same name for both variables. |
I see! I'm a bit wary about using the |
Would th-abstaction help?
ehh... I guess? That strikes me as more fragile, but I don't do much metaprogramming. |
|
Consider the following code:
There are two ways to make this
surjective
-friendly. We could list the three values separately:Or we could split out the
[True, False]
bit into its ownsurjective
-friendly definition:I personally like this second approach, but
surjective
shouldn't be in the business of recommending a coding style. To support the style of the original definition, we'd need to transform small patterns into bigger patterns:Semantically,
transform
is another macro which, likesurjective
, gathers the calls tocovers
within its scope. Then, it transforms them (in this case fromx
toJust x
), and passes them on to the surroundingsurjective
macro, who will gather both the patterns produced bytransform
(in this caseJust True
andJust False
) and the other pattern defined outside oftransform
(in this caseNothing
).Since
covers
has typeCovers a
,transform
must bind its owncovers'
function, of typeCovers Bool
.Suggested by @rpglover64 in the same reddit comment as #8's suggestion.
The text was updated successfully, but these errors were encountered: