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

NotContains and IsDistinct constraints for HList #548

Merged
merged 3 commits into from Mar 7, 2016

Conversation

vpavkin
Copy link
Contributor

@vpavkin vpavkin commented Feb 18, 2016

There was a conversation on gitter regarding these, but some urgent stuff weighted in short after.
So I leave it here for better times to be either merged or rejected :)

Note:
An implementation of IsDistinctConstraint without use of NotContainsConstraint can be following (with a use of ambiguous implicits trick):

trait IsDistinctConstraint[L <: HList]

object IsDistinctConstraint {
  def apply[T <: HList](implicit ev: IsDistinctConstraint[T]): IsDistinctConstraint[T] = ev

  // we have to build chain here so that ambiguous breaker works for smth like A :: B :: B :: HNil
  implicit def unique0 = new IsDistinctConstraint[HNil] {}
  implicit def unique1[H, T <: HList](implicit ev: IsDistinctConstraint[T]) = new IsDistinctConstraint[H :: T] {}

  implicit def uniqueAmb1[H <: HList, T](implicit ev: Selector[H, T]): IsDistinctConstraint[T :: H] = 
    shapeless.unexpected
  implicit def uniqueAmb2[H <: HList, T](implicit ev: Selector[H, T]): IsDistinctConstraint[T :: H] = 
    shapeless.unexpected
}

Maybe it's a better choice...

@milessabin
Copy link
Owner

This looks very promising, but the RC cycle for 2.3.0 has already started so I'm afraid I'm going to have to punt it until 2.3.1.

@milessabin milessabin added this to the shapeless-2.3.1 milestone Feb 20, 2016
@vpavkin
Copy link
Contributor Author

vpavkin commented Feb 20, 2016

Sure, would be great! :)

@milessabin
Copy link
Owner

LGTM! Many thanks ... merging :-)

milessabin added a commit that referenced this pull request Mar 7, 2016
NotContains and IsDistinct constraints for HList
@milessabin milessabin merged commit b64b012 into milessabin:master Mar 7, 2016
@vpavkin vpavkin deleted the hlist-is-distinct-typeclass branch March 7, 2016 10:14
@milessabin milessabin modified the milestone: shapeless-2.3.1 May 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants