Comments (6)
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.
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.
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.
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.
Also I assume your case isn't actually
Boolean
, since you could usenot
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.
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)
- Overlapping instances found HOT 24
- No separation between Enumerable and FinitelyEnumerable HOT 1
- BoundedOrd HOT 1
- Inconsistent behavior of enumFromTo for bounded enums HOT 2
- UnboundedEnum HOT 6
- BoundedEnum instance for Int has invalid cardinality HOT 2
- Incorrect assumptions from BoundedEnum laws. HOT 3
- Why isn't BoundedEnum constraint used in defaultSucc and defaultPred? HOT 2
- upFromIncluding :: ∀ a u. Enum a => Unfoldable u => a -> NonEmpty u a HOT 2
- move Cardinality to type level HOT 3
- Consider a SmallBounded type
- `toEnum` modulo `Cardinality a`
- `charToEnum` implementation is wrong HOT 1
- Define BoundedEnum-like class using type-level Ints
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-enums.