Git Product home page Git Product logo

Comments (6)

garyb avatar garyb commented on June 11, 2024 1

I think there might be room for a CyclicalBoundedEnum type class:

I thought about that too, but I think the class would be basically lawless, and I'm not sure it gives you anything that couldn't be defined in terms of BoundedEnum already. Just fewer instances to implement I guess.

from purescript-enums.

Masynchin avatar Masynchin commented on June 11, 2024 1

For something dynamic like a track list I'd perhaps do something with an infinite (lazy) list, use a zipper, or just a pair of my own functions to handle it.

Yeah, I currently do Track type with rotate :: Track -> Track function. Maybe Enum for Track is not that suitable as my own type, but an interesting idea at start. @garyb and @JordanMartinez thanks for help!

from purescript-enums.

garyb avatar garyb commented on June 11, 2024

That would break the laws of Enum as defined here, so I guess the answer is "because we chose Enum to mean something that is incompatible with this idea". 😉

Maybe cyclicSucc / cyclicPred functions could be defined in terms of BoundedEnum? That way they're not breaking any laws and they're taking advantage of the existing definitions.

(Also I assume your case isn't actually Boolean, since you could use not for that.)

from purescript-enums.

JordanMartinez avatar JordanMartinez commented on June 11, 2024

I think there might be room for a CyclicalBoundedEnum type class:

class CyclicalBoundedEnum where
  skip :: Int -> a -> a
  cyclicalBottom :: a
  cyclicalTop :: a

If something is cyclical, then is it likely that succ/pred could be succeeded with skip?

from purescript-enums.

Masynchin avatar Masynchin commented on June 11, 2024

Also I assume your case isn't actually Boolean, since you could use not for that.

My thoughts were about tracks list, where succ of last track returns first track. With Boolean example I tried to show that Maybe only needs for bounds, when in other realization it can return min bound instead. I also have checked how it is done in Haskell - it has signature succ :: a -> a. I don't have much experience in Haskell, but think it is what I wrote above.

from purescript-enums.

garyb avatar garyb commented on June 11, 2024

Yeah, Enum in Haskell is quite different, it's only really intended for statically sized things in PureScript. Also its version of succ is still partial, if you try succ True it raises an error, so it's just not exposed in the type the way it is here.

For something dynamic like a track list I'd perhaps do something with an infinite (lazy) list, use a zipper, or just a pair of my own functions to handle it.

from purescript-enums.

Related Issues (15)

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.