Newtypes (again)

The current way how you write newtypes (and their instances) is repetitive and more than annoying than it could be. I have this macro in vscode:

newtype ${1} = ${1} String
derive instance nt${1} :: Newtype ${1} _
derive newtype instance readForeign${1} :: ReadForeign ${1}
derive newtype instance writeForeign${1} :: WriteForeign ${1}
derive newtype instance eq${1} :: Eq ${1}
derive newtype instance show${1} :: Show ${1}
  show = genericShow

Which perfectly describes the amount of boilerplate required for a newtype. I have also found the thread Adding syntax for annotations on declarations which lists some ideas, but doesn’t remove a whole lot from the above IMO. Haskell does solve that reasonably well with its deriving clauses, where not every single individual instance requires a new line and a name.

I think the new annotation syntax in the linked thread should be considered for a solution here.

4 Likes