-
-
Save anonymous/034395b59ecec2a5a96e to your computer and use it in GitHub Desktop.
Matrix constructor example with Slang's mixfix operators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
group juxtaposition | |
// … denotes operator holes | |
// ⁕ denotes that the previous name part is a separator, and the operator is variadic | |
group matrixBrackets = "⟦…,⁕…⟧" | |
// at the moment the following rule isn't really needed, because any expression can appear in a closed hole | |
// (a closed hole is one that has operator name parts on both left and right) | |
// but if we imagine that an operator group such as juxtaposition could be "disabled by default" | |
// then we would here say that juxtaposition is allowed to appear in the closed holes of matrixBrackets | |
matrixBrackets -> juxtaposition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Row = (a: Int, b: Int) | |
extending Int { | |
def juxtaposition(that: Int): Row = (this, that) | |
} | |
// at the moment ⟦…,⁕…⟧ is not a valid identifier unless wrapped in `...` | |
def `⟦…,⁕…⟧`(row1: Row, row2: Row) = // create matrix | |
// since juxtaposition is defined to bind more tightly than matrixBrackets, it can appear in these holes | |
// separated by commas | |
def main() = ⟦1 2, | |
3 4⟧ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment