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

Projects
None yet
2 participants
@vpavkin
Contributor

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

This comment has been minimized.

Owner

milessabin commented Feb 20, 2016

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 the Feature label Feb 20, 2016

@milessabin milessabin added this to the shapeless-2.3.1 milestone Feb 20, 2016

@vpavkin

This comment has been minimized.

Contributor

vpavkin commented Feb 20, 2016

Sure, would be great! :)

@milessabin

This comment has been minimized.

Owner

milessabin commented Mar 7, 2016

LGTM! Many thanks ... merging :-)

milessabin added a commit that referenced this pull request Mar 7, 2016

Merge pull request #548 from vpavkin/hlist-is-distinct-typeclass
NotContains and IsDistinct constraints for HList

@milessabin milessabin merged commit b64b012 into milessabin:master Mar 7, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@vpavkin vpavkin deleted the vpavkin:hlist-is-distinct-typeclass branch Mar 7, 2016

@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