Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • S sweet-core
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 62
    • Issues 62
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • sweet-js
  • sweet-core
  • Merge requests
  • !665

Implement custom operators

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Tim Disney requested to merge feature/add-custom-operators into master Apr 03, 2017
  • Overview 3
  • Commits 3
  • Pipelines 0
  • Changes 12

Fixes #517 (closed).

Easier than I thought it would be.

I chose to go with using the same declarator form that syntax and syntaxrec use. Made the implementation much simpler than other forms since it can just piggyback on the work done for syntax/syntaxrec in terms of binding and loading into the compiletime env.

It's not the most user-friendly syntactic form but we can always provide a macro the give some sugar (I suspect a declaration form would work nicely but we can play with that later).

I've just implemented binary and prefix unary. Postfix unary requires a few more changes that I'd like to do later.

operator >>= left 3 = (left, right) => {
  return #`${left}.chain(${right})`;
}
class IdMonad {
  constructor(value) {
    this.value = value;
  }
  chain(f) {
    return f(this.value);
  }
}

function Id(value) {
  return new IdMonad(value);
}

let result = Id(1) >>= v => Id(v + 1)
                   >>= v => Id(v * 10);
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: feature/add-custom-operators