35 ms·
The "fact(match)" is very strange. In Haskell you have "lambda-case" and in Ocaml you have "fun" as syntaxes to define lambdas that pattern-match on the argumen
by ufo 12y ago
The "fact(match)" is very strange. In Haskell you have "lambda-case" and in Ocaml you have "fun" as syntaxes to define lambdas that pattern-match on the argument.
That said, I really like the inclusion of async and a DSL for documents. These two are things that benefit a lot from having language support.
- breuleux 12y ago"fact(match)" is just making use of a generic feature: the "match" keyword in a pattern dictates that the body defines a sequence of sub-patterns to match at that position. An argument uses pattern syntax, so it works there, but it works in other situations, for example this contrived example: f(x, y) = match x: {m, n} -> match m: <= 0 -> n + y else -> m + n + y n -> n + y Can be rewritten: f(match x, y) = {match m, n} -> <= 0 -> n + y else -> m + n + y n -> n + y So you can match hierarchically like that (sorry if the example is strange, it's not supposed to mean anything).
- ufo 12y agoIs there any other language that does this? For me the second example doesn't look better than the first one.
- breuleux 12y agoI haven't seen the feature elsewhere. The second example looks better to me (syntax highlighting helps) and reduces redundancy and indent, but I guess views may vary on this. Good to know!
- ufo 12y agoIf your goal is to reduce redundancy than I think a "lambda-case" syntax might be a better fit. As a bonus it also lets you use this feature on anonymous functions! https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/syntax-extns.html#lambda-case https://downloads.haskell.org/~ghc/latest/docs/html/users_gu... http://stackoverflow.com/questions/1604270/what-is-the-different-between-fun-and-function-keywords http://stackoverflow.com/questions/1604270/what-is-the-diffe...
- breuleux 12y agoThere already is a "lambda-case" syntax. "fact(match) = ..." is sugar for "fact = match -> ...". If one works, then so does the other. Personally I much prefer the way I do it, because it is more powerful, works in more places, and requires no new syntactic forms.
- adrusi 12y agoI haven't seen this specifically, but I have seen other languages move common top level behaviors within functions into parameter lists. Ruby, dart, coffescript allow setting of instance variables from the parameter list: class Example constructor: (@name) -> # do stuff class Example constructor: (name) -> @name = name # do stuff Jonathan Blow's language allows the `using` keyword in parameter list, which desugars in much the same way. I'm personally not a big fan of using this technique for pattern matching, but its better than requiring explicit match blocks everywhere (like Scala and rust).