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

Convert type classes to LF type synonyms #4023

Merged
merged 1 commit into from
Jan 24, 2020
Merged

Convert type classes to LF type synonyms #4023

merged 1 commit into from
Jan 24, 2020

Conversation

cocreature
Copy link
Contributor

This is still a draft PR until type synonyms are ready across the stack (in particular the Scala side is still missing completely) but the conversion should work and I’m able to run daml build with this on a large DAML codebase.

changelog_begin
changelog_end

Pull Request Checklist

  • Read and understand the contribution guidelines
  • Include appropriate tests
  • Set a descriptive title and thorough description
  • Add a reference to the issue this PR will solve, if appropriate
  • Include changelog additions in one or more commit message bodies between the CHANGELOG_BEGIN and CHANGELOG_END tags
  • Normal production system change, include purpose of change in description

NOTE: CI is not automatically run on non-members pull-requests for security
reasons. The reviewer will have to comment with /AzurePipelines run to
trigger the build.

@cocreature cocreature requested review from a user and nickchapman-da January 13, 2020 13:25
@cocreature cocreature force-pushed the typeclass-synonym branch 4 times, most recently from 0790916 to dd64798 Compare January 17, 2020 15:42
@cocreature
Copy link
Contributor Author

@associahedron Both good ideas, I’ve incorporated your suggestions. Thanks!

@cocreature cocreature force-pushed the typeclass-synonym branch 2 times, most recently from 26a88f4 to 7306e3f Compare January 23, 2020 10:51
@@ -1,5 +1,3 @@
{-# LANGUAGE ConstrainedClassMethods #-}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is enabled by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it isn’t. The GHC docs lied to me by claiming that MultiParamTypeclasses imply ConstrainedClassMethods.

@@ -9,5 +7,8 @@ class A t where
foo : t -> t
bar : Eq t => t -> t

class B t where
baz : B b => b -> t
-- This would create a recursive type synonym.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We decided to just disable this for now. We don’t use this on our large internal DAML codebase. There is a reasonable workaround with manual dictionary passing and if it does become a record we could either handle this in the LF conversion or support infinite types (something like OCaml’s -rectypes).

Copy link

Choose a reason for hiding this comment

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

Seems reasonable to me. I don't know of any natural examples of a class that requires itself as a constraint.

@@ -32,7 +32,6 @@ for LF_VERSION in $PKG_DB/*; do
stdlib=$LF_VERSION/daml-stdlib-*.dalf
prim=$LF_VERSION/daml-prim.dalf
$DIFF -b -u <(get_serializable_types $stdlib) <(cat <<EOF
"DA.Upgrade:MetaEquiv"
Copy link
Contributor Author

@cocreature cocreature Jan 23, 2020

Choose a reason for hiding this comment

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

This is a typeclass with no methods which was therefore serializable but is now translated to Unit.

@cocreature cocreature marked this pull request as ready for review January 23, 2020 14:00
@cocreature cocreature requested a review from a user January 23, 2020 14:46
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

pure $ ERecProj (fromTCon recTyp) fldName scrutinee' `ETmApp` EUnit
if envLfVersion env `supports` featureTypeSynonyms
then pure $ EStructProj fldName scrutinee' `ETmApp` EUnit
else pure $ ERecProj (fromTCon recTyp) fldName scrutinee' `ETmApp` EUnit
Copy link

Choose a reason for hiding this comment

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

I think you can replace this if expression by using the helper function,

pure $ mkDictProj env (fromTCon recTyp) fldName scrutinee' `ETmApp` EUnit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, fixed. Thank you!

@@ -9,5 +7,8 @@ class A t where
foo : t -> t
bar : Eq t => t -> t

class B t where
baz : B b => b -> t
-- This would create a recursive type synonym.
Copy link

Choose a reason for hiding this comment

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

Seems reasonable to me. I don't know of any natural examples of a class that requires itself as a constraint.

changelog_begin
changelog_end
@mergify mergify bot merged commit 3496ce0 into master Jan 24, 2020
@mergify mergify bot deleted the typeclass-synonym branch January 24, 2020 09:24
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.

2 participants