Format class declarations #236

Open
opened 2019-06-19 00:51:52 +02:00 by tfausak · 0 comments
tfausak commented 2019-06-19 00:51:52 +02:00 (Migrated from github.com)

Brittany does not currently format type class declarations. Instead it simply passes them through. That's fine for a lot of cases because defining new type classes is less common than adding instances. Also type classes often aren't very complicated syntactically, so it's not too burdensome to format them by hand. All that being said, it would be great if Brittany could format them. For example, consider this type class declaration:

-- brittany --columns 20
class SomeVeryLongConstraint => SomeVeryLongTypeClass someVeryLongTypeName where
 someVeryLongMethodName :: someVeryLongTypeName -> someVeryLongTypeName
 someVeryLongMethodName someVeryLongVariableName = someVeryLongVariableName

I chose 20 columns arbitrarily in order to force the layout onto multiple lines. Otherwise the result isn't super interesting.

I'm not exactly sure how I'd like that to be formatted, but maybe something like this?

class
  SomeVeryLongConstraint
  => SomeVeryLongTypeClass
     someVeryLongTypeName
 where
  someVeryLongMethodName
    :: someVeryLongTypeName
    -> someVeryLongTypeName
  someVeryLongMethodName someVeryLongVariableName
    = someVeryLongVariableName
Brittany does not currently format type class declarations. Instead it simply passes them through. That's fine for a lot of cases because defining new type classes is less common than adding instances. Also type classes often aren't very complicated syntactically, so it's not too burdensome to format them by hand. All that being said, it would be great if Brittany could format them. For example, consider this type class declaration: ``` hs -- brittany --columns 20 class SomeVeryLongConstraint => SomeVeryLongTypeClass someVeryLongTypeName where someVeryLongMethodName :: someVeryLongTypeName -> someVeryLongTypeName someVeryLongMethodName someVeryLongVariableName = someVeryLongVariableName ``` I chose 20 columns arbitrarily in order to force the layout onto multiple lines. Otherwise the result isn't super interesting. I'm not exactly sure how I'd like that to be formatted, but maybe something like this? ``` hs class SomeVeryLongConstraint => SomeVeryLongTypeClass someVeryLongTypeName where someVeryLongMethodName :: someVeryLongTypeName -> someVeryLongTypeName someVeryLongMethodName someVeryLongVariableName = someVeryLongVariableName ```
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hexagoxel/brittany#236
There is no content yet.