Skip to content

Add deriving for Data.Newtype#2326

Merged
garyb merged 2 commits intopurescript:masterfrom
garyb:derive-newtype
Sep 24, 2016
Merged

Add deriving for Data.Newtype#2326
garyb merged 2 commits intopurescript:masterfrom
garyb:derive-newtype

Conversation

@garyb
Copy link
Copy Markdown
Member

@garyb garyb commented Sep 23, 2016

Resolves #2314

throwError . errorMessage $ CannotDeriveNewtypeForData name
go (DataDeclaration Newtype name _ dctors) = do
checkNewtype name dctors
let (ctorName, [ty]) = head dctors
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not match this as a singleton above?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Could do, but if you have an invalid newtype you'll get an error about an un-derivable class before you get the error that the newtype is invalid (since the check is made during type checking), which seems... not very useful.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah ok. We can revisit this after I move deriving into the solver then.

"purescript-st": "1.0.0-rc.1",
"purescript-partial": "1.1.2"
"purescript-partial": "1.1.2",
"purescript-newtype": "0.1.0"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I assume this will be bumped to 1.0 eventually?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, I just made a release so we could add the test thing - we'll need to make a 2.0 prelude anyway, so when that is released the dependency will need bumping in newtype, at which point it'll be worth releasing as 1.0... phew 😉

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need Prelude 2.0?

go (DataDeclaration Data name _ _) =
throwError . errorMessage $ CannotDeriveNewtypeForData name
go (DataDeclaration Newtype name _ dctors) = do
checkNewtype name dctors
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will be caught at the newtype definition, won't it?

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Sep 23, 2016

👍 Looks good, thanks!

I keep wondering about implementing GHC-style Generics as well, but that's probably too much work for 0.10. Hopefully we can add it in a minor release as a non-breaking change.

@garyb
Copy link
Copy Markdown
Member Author

garyb commented Sep 24, 2016

Tests are passing again now - looks like one of them was depending on a misbehaving Show instance for Number that was fixed some time after the Prelude dependency we were using previously.

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Sep 24, 2016

Looks good!

@garyb garyb merged commit da9b49f into purescript:master Sep 24, 2016
@garyb garyb deleted the derive-newtype branch September 24, 2016 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants