-
Notifications
You must be signed in to change notification settings - Fork 158
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
WIP: Type class that combines RefType and Validate #193
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Current coverage is 98.51% (diff: 95.00%)
|
fthomas
force-pushed
the
topic/RefinedType
branch
from
July 26, 2016 21:13
48e3002
to
e79ee1d
Compare
+1. Much simpler. Im keen to try it out in a project! |
Superseded by #369 which also contains the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds the
RefinedType
type class that combinesRefType
andValidate
instances for a refined typeF[T, P]
. The motivating example for this type class was given by @benhutchison on Gitter. Abstracting overRefType.applyRef
currently requires a lot of type ceremony:The goal is to allow calls like
refineEff[PosInt](5)
wherePosInt
is an alias forInt Refined Positive
and the base typeInt
can be inferred from the parameter ofapply
. WithRefinedType
, this can be simplified to:What has improved with
RefinedType
:apply
has two fewer type parametersapply
has two fewer implicit parametersRefType.applyRef[S].apply(t)
becamert.refine(t)
In general I think this is a win. The only downside is that we still require the
ApplyRefPartiallyAppliedExt
class to partially apply the refined typeS
and to let the base typeT
be inferred.Also the combination of
RefType
andValidate
is very common (e.g., type class instances of 3rd-party libraries for refined types almost always require the combination of these two), so it is natural to combine them. It also makes the implementation of refined simpler in some cases.It is unfortunate that the names
RefType
andRefinedType
are very similar. This type class makes me regret the nameRefType
. Maybe something likeCarrierType
orWrapperType
would have been a better choice.