-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add common PropName, AttrName, ClassName #30
Conversation
src/Web/HTML/Common.purs
Outdated
derive instance newtypeClassName :: Newtype ClassName _ | ||
derive newtype instance eqClassName :: Eq ClassName | ||
derive newtype instance ordClassName :: Ord ClassName | ||
derive newtype instance semigroupClassName :: Semigroup ClassName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
derive newtype instance semigroupClassName :: Semigroup ClassName | |
derive newtype instance semigroupClassName :: Semigroup ClassName | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have a problem with this instance - I can see that argument for wanting to support "class1 class2"
as considered to be a class name, as unless we actually make a smart constructor that rejects names with spaces there's no guarantee it's happening, but now there's a problem with this meaning of this instance too IMO:
If I have x :: ClassName
and y :: ClassName
it seems like the result of that should be ClassName (unwrap x <> " " <> unwrap y)
. The name ClassName
suggests to me that the value is not part of a class name, but it's a whole class name, so by combining them without a space it's constructing a new class name, not combining two class names.
But I can also see why that might be unexpected for some people, which is kinda why I don't like the instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a good point, and it's the reason why in my own applications I have a separate classes
function which concatenates with spaces (unlike a standard semigroup instance, which concatenates without spaces (rightly so)). I agree that we shouldn't have a semigroup instance as the law-abiding one is not what you probably want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would still be law abiding if it included the space, it's just that I think either instance we choose has the potential to trip people up, depending on how they see the type ("it's just a newtype string wrapper" vs a thing with its own semantics).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, now I can't remember why I thought that was a semigroup law; I must be thinking of the left/right identity laws for monoid.
For what it's worth, we could assert that this is a thing with its own semantics, where ClassName
represents a distinct CSS class, and where append includes a separating space. I don't think I've had a conversation with someone using this type in the Halogen world where they saw it as anything else, though that's a small anecdote.
Regardless, if I'm overconfident and the camps are split then it's much better not to have an instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It arose here a while back: purescript-halogen/purescript-halogen#512 🙁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I say we take it out to avoid the confusion. Thanks for the link!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either instance is a perfectly fine semigroup; semigroups only need associativity, and the space-adding version’s associativity follows from normal string concatenation being associative. The difference is that if you use the space-adding Semigroup, you can’t have a Monoid instance because there’s no identity element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I say we take it out to avoid the confusion.
Will do. For reference here is where the instance was added for Halogen purescript-halogen/purescript-halogen#451
I've left a comment on the relevant Halogen issue as well. |
src/Web/HTML/Common.purs
Outdated
|
||
import Data.Newtype (class Newtype) | ||
|
||
-- | A type-safe wrapper for property names. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure calling these "type safe" is exactly right, maybe just "semantic"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to remove it. Just copying what already exists in Halogen https://github.com/purescript-halogen/purescript-halogen/blame/c8b50378b948fcba9e10d75da718fc7dae3a609f/src/Halogen/HTML/Core.purs#L171
src/Web/HTML/Common.purs
Outdated
derive instance newtypeClassName :: Newtype ClassName _ | ||
derive newtype instance eqClassName :: Eq ClassName | ||
derive newtype instance ordClassName :: Ord ClassName | ||
derive newtype instance semigroupClassName :: Semigroup ClassName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have a problem with this instance - I can see that argument for wanting to support "class1 class2"
as considered to be a class name, as unless we actually make a smart constructor that rejects names with spaces there's no guarantee it's happening, but now there's a problem with this meaning of this instance too IMO:
If I have x :: ClassName
and y :: ClassName
it seems like the result of that should be ClassName (unwrap x <> " " <> unwrap y)
. The name ClassName
suggests to me that the value is not part of a class name, but it's a whole class name, so by combining them without a space it's constructing a new class name, not combining two class names.
But I can also see why that might be unexpected for some people, which is kinda why I don't like the instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After hearing @garyb's feedback I agree and think his suggestions ought to be applied.
We can fix the CI error by providing the annotation |
Out of curiosity, would anyone be able to shed light on why these types were added to |
See #29