Git Product home page Git Product logo

Comments (8)

fthomas avatar fthomas commented on July 18, 2024

I suspect that calculating MinValue and MaxValue of Crazy is the culprit.

from refined.

toddburnside avatar toddburnside commented on July 18, 2024

That was quick!
I should have mentioned in the comment, Equal[5] Or Greater[5] is fine.

from refined.

steinybot avatar steinybot commented on July 18, 2024

It seems @fthomas suspicions are correct. This does it:

object Main extends App {
  type Crazy = Int Refined (Greater[5] Or Equal[5])
  val min: Min[Crazy] = implicitly[Min[Crazy]]
}

from refined.

steinybot avatar steinybot commented on July 18, 2024

Oh Or is going to use Min.validateMin which will start at Int.MinValue and step up one at a time until it finds a valid value. No wonder.

Would something like this work?

  implicit def orMin[F[_, _], T, L, R](implicit
      rt: RefType[F],
      ml: Min[F[T, L]],
      mr: Min[F[T, R]],
      at: Adjacent[T],
      v: Validate[T, L Or R]
  ): Min[F[T, L Or R]] =
    Min.instance(rt.unsafeWrap(findValid(at.min(rt.unwrap(ml.min), rt.unwrap(mr.min)))))

from refined.

fthomas avatar fthomas commented on July 18, 2024

Would something like this work?

Yes, I think so. But since this is Or, the findValid call should not be needed.

from refined.

steinybot avatar steinybot commented on July 18, 2024

Oh good point. I realised that still isn't going to cut it. There isn't one for Equal.

This seems to fix it:

  implicit def orMin[F[_, _], T, L, R](implicit
      rt: RefType[F],
      ml: Min[F[T, L]],
      mr: Min[F[T, R]],
      at: Adjacent[T],
      v: Validate[T, L Or R]
  ): Min[F[T, L Or R]] =
    Min.instance(rt.unsafeWrap(at.min(rt.unwrap(ml.min), rt.unwrap(mr.min))))
  
  implicit def equalMin[F[_, _], T, N](implicit
      rt: RefType[F],
      wn: WitnessAs[N, T]
  ): Min[F[T, Equal[N]]] =
    Min.instance(rt.unsafeWrap(wn.snd))

from refined.

fthomas avatar fthomas commented on July 18, 2024

It probably makes sense to add these two instances for Min and Max.

On a side note: The built-in GreaterEqual[N] should be preferred over Greater[N] Or Equal[N].

from refined.

toddburnside avatar toddburnside commented on July 18, 2024

On a side note: The built-in GreaterEqual[N] should be preferred over Greater[N] Or Equal[N].

Agreed. I found this example/problem in a different library and I'm putting in a PR to do just that. 😄

from refined.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.