Skip to content

Attributes aren't type safe #84

@cchalmers

Description

@cchalmers

There's three different types of Attribute but all attributes can be used with the standard Attribute.

It's an easy mistake to wrap up an attribute incorrectly, I've seen (and done) it a few times. After spending over an hour debugging to find out splitAttr does this too I want this to be fixed :)

One way is to use data kinds:

data AttrKind = Attr | MAttr | TAttr

class AttributesClass where
  type AttrType :: AttrKind

applyAttribute :: (AttributeClass a, AttrType a ~ Attr, HasStyle d) => a -> d -> d
applyTAttribute :: (AttributeClass a, AttrType a ~ TAttr, HasStyle d) => a -> d -> d
atAttr :: (AttributeClass a, AttrType a ~ Attr) :: Lens' (Style v n) (Maybe a)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions