Skip to content
This repository has been archived by the owner on Oct 12, 2019. It is now read-only.

a simple solution to hygiene problem #81

Merged
merged 5 commits into from
May 19, 2017
Merged

a simple solution to hygiene problem #81

merged 5 commits into from
May 19, 2017

Conversation

liufengyun
Copy link
Owner

This is a simple while practical solution to the hygiene problem: it still allows programmers to do the hack if scala.gestalt.options.unsafe is imported. By default, only fully-qualified name or symbol-based name is supported.

When scala supports literal types, we can do better with the API:

      def Ident(name: "_root_"): Tree
      def Ident(name: "scala")(implcit dummy: C): Tree

@liufengyun
Copy link
Owner Author

It's really nice that the implementation of monadless is hygienic, and optional is partly hygienic.

@liufengyun liufengyun requested a review from valdisxp1 May 19, 2017 08:00
@liufengyun liufengyun mentioned this pull request May 19, 2017
Copy link
Collaborator

@valdisxp1 valdisxp1 left a comment

Choose a reason for hiding this comment

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

This is great, forcing to use symbols, existing Idents or full paths by default makes sense.
Unsafe can also be imported in small scopes makes for good design.

Other than the two minor comments on implementation, this looks good.

prefix.select(name)
}

TypeSelect(prefix, parts.last)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be a fold over TypeTree not TermTree.
It is possible to eliminate the recursive calls if we handle the head specially not the last.

parts.tail.foldLeft[TypeTree](TypeSelect(tree,parts.head)){
  (prefix, name) =>
    TypeSelect(prefix, name)
}

Copy link
Owner Author

Choose a reason for hiding this comment

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

In a type select such as scala.collection.Set, only the last part is TypeSelect, scala.collection is still Select.

prefix.select(name)
}

Select(prefix, parts.last)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be done more easily

parts.foldLeft[TermTree](tree) {
  (prefix, name) =>
       Select(prefix, name)  
 }

Copy link
Owner Author

Choose a reason for hiding this comment

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

Indeed, thanks a lot.

@liufengyun liufengyun merged commit 5eee37a into master May 19, 2017
@liufengyun liufengyun deleted the hygiene branch May 19, 2017 13:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants