Skip to content
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

Merged
merged 3 commits into from
Dec 17, 2020

Conversation

milesfrain
Copy link
Contributor

See #29

derive instance newtypeClassName :: Newtype ClassName _
derive newtype instance eqClassName :: Eq ClassName
derive newtype instance ordClassName :: Ord ClassName
derive newtype instance semigroupClassName :: Semigroup ClassName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
derive newtype instance semigroupClassName :: Semigroup ClassName
derive newtype instance semigroupClassName :: Semigroup ClassName

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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).

Copy link
Contributor

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.

Copy link
Member

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 🙁

Copy link
Contributor

@thomashoneyman thomashoneyman Dec 11, 2020

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!

Copy link
Contributor

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.

Copy link
Contributor Author

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

@thomashoneyman
Copy link
Contributor

I've left a comment on the relevant Halogen issue as well.


import Data.Newtype (class Newtype)

-- | A type-safe wrapper for property names.
Copy link
Member

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"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

derive instance newtypeClassName :: Newtype ClassName _
derive newtype instance eqClassName :: Eq ClassName
derive newtype instance ordClassName :: Ord ClassName
derive newtype instance semigroupClassName :: Semigroup ClassName
Copy link
Member

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.

Copy link
Contributor

@thomashoneyman thomashoneyman left a 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.

@thomashoneyman
Copy link
Contributor

We can fix the CI error by providing the annotation newtype PropName :: Type -> Type.

@nsaunders
Copy link

nsaunders commented May 11, 2023

Out of curiosity, would anyone be able to shed light on why these types were added to web-html instead of web-dom? Some of the seemingly related functions that live in web-dom like className and getAttribute made me wonder about this... Thanks in advance for any thoughts you can share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants