Skip to content
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

Add refine function that takes a complete refined type as parameter #78

Closed
fthomas opened this issue Oct 22, 2015 · 3 comments · Fixed by #79
Closed

Add refine function that takes a complete refined type as parameter #78

fthomas opened this issue Oct 22, 2015 · 3 comments · Fixed by #79

Comments

@fthomas
Copy link
Owner

fthomas commented Oct 22, 2015

When working with type aliases like type Minute = Int Refined Interval[W.0.T, W.59.T] it would be nice to have a refine function for refining runtime values that takes the refined type as parameter:

refine[Minute](x): Either[String, Minute]

For literals a type ascription is enough right now, e.g.: 12: Minute

If we have this, type_aliases.md should be updated with usages of that function.

@fthomas
Copy link
Owner Author

fthomas commented Oct 23, 2015

Something like this works:

  def refine[FTP] = new RefineAux2[FTP]

  class RefineAux2[FTP] {
    def apply[F[_, _], T, P](t: T)(implicit ev: FTP =:= F[T, P], rt: RefType[F], v: Validate[T, P]) =
      rt.refine[P](t)
  }

Now the hard part: how to call it and where to put it.

@fthomas
Copy link
Owner Author

fthomas commented Oct 24, 2015

I think I'm going to put it in the RefType companion. refine and refineM are in the RefType trait where the type parameter F[_, _] is already known. For the above function F[_, _] is given by the type parameter FTP so it makes sense to have it on the companion which is not related to any F[_, _]. Similar to RefType.apply it also summons an instance based on the given type parameter.

@fthomas
Copy link
Owner Author

fthomas commented Oct 24, 2015

WRT naming: I'm leaning to applyRef which is short for "apply this refinement to the given value". With the type parameter FTP one specifies the base type T, the predicate P, and the refinement carrier F[_, _], so the complete refinement is given by this parameter.

fthomas added a commit that referenced this issue Oct 24, 2015
closes #78. This commit still misses documentation. I'll add them later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant