r/purescript • u/daigoro_sensei • Jan 21 '23
Looking to define some colours. Just checking but there is no `0xffffff` style hex Int type right?
Anyone have any good ideas here? Not a fan of using a hex String and then having to deal with then resulting Maybe when parsing its value. Also feels awkward to store a colour as a decimal value. Maybe rgb is the way...
3
Upvotes
2
u/Herku Jan 21 '23
But there is: Try PureScript
It even suggests the usage in the documentation of the module right under your mentioned function fromHexString.
2
u/CubOfJudahsLion Jan 22 '23
Sure, there are hex literals. Just like you wrote them.
When I dealt with color, though, I defined a
data ColorwithRGB(r, g, b)and aRGBA(r, g, b, a)variants with a hand-writtenShowimplementation to match the correct format. I defined some constants for the standard named colors as a separate variant. The real challenge is in parsing colors back from, say, stylesheets, as you gotta learn to parse all of the named colors and the several notations.