Better HN
topnewbestaskshowjobs
Log inSign up

natefaubion

138 karma · joined Jun 7, 2011 (15y ago) · 20 submissions

Submissions

comment 7y ago · link · parent

It's something that comes from Haskell. The `where` keyword always starts a new layout/indentation context. It's not strictly necessary and there are ways around it, so it's just a point of consistency.

comment 7y ago · link · parent

Yes, I'm not saying there aren't usages for them in general, but PureScript currently occupies a niche that doesn't get down to the level of binary file formats. This change is more about "only supporting what we need to right now", rather than "we don't like binary literals". As noted elsewhere, it's not difficult to add support for them when we need to.

comment 7y ago · link · parent

We found no usages of it in the wild. If there is real-world need for them, we'll consider adding them back.

4.

Sparkler -- Native pattern matching for JavaScript using sweet.js macros(github.com ↗)

2 points · by natefaubion · 13y ago · discuss

comment 13y ago · link · parent

There aren't native modules in JS (though they are coming in ES6). The module pattern is a way of having private scope by wrapping everything in a closure. So yes, the module pattern just creates a closure and returns an object (or assigns to global scope) with its public members.

comment 13y ago · link · parent

A cleaner way of doing the immediately-invoking function in CS is to use a `do` statement.

    MyModule = do ->
      # module body
No need for any parens.

7.

ReactiveCocoa -- an Objective-C framework for Functional Reactive Programming.(github.com ↗)

2 points · by natefaubion · 13y ago · discuss

comment 13y ago · link · parent

If you're interested in doing some of this stuff in JS, there's sweet.js[1] for macros. I've also implemented some similar stuff as libraries: adt.js[2], matches.js[3], and tailrec.js[4]. By implementing them as libraries, I've given up some of the nicety of native-looking syntax, but it requires no preprocessing and only ES3.

[1] http://sweetjs.org/

[2] https://github.com/natefaubion/adt.js

[3] https://github.com/natefaubion/matches.js

[4] https://github.com/natefaubion/tailrec.js

comment 13y ago · link · parent

With pattern matching, the term on the left is a destructuring of the term on the right. Using a static instance like that isn't what you normally do in practice, but rather something like:

    myfoo = Foo(4, Bar(3, 8))
    with patterns:
        Foo(x, Bar(3, z)) << myfoo
        
So in this case, the assertion will only pass if the Foo contains a Bar in the second slot, and that Bar contains a 3 in its first slot, while also binding the 4 and 8 to their own names, x and z respectively.

10.

Tailrec.js -- Dead simple auto-trampolining for Javascript(github.com ↗)

5 points · by natefaubion · 14y ago · 3 comments

comment 14y ago · link · parent

I find it helps when you use short-circuiting. The returns are the first thing you see, making it more obvious what is going on.

  myfn = (arg) ->
    return 1 if arg is "one"
    return 2 if arg is "two"
    return arg.toInt()
This is obviously a little contrived with such a short method, but helps when you have stuff to do between conditional returns.

comment 14y ago · link · parent

That's along similar lines, but more like guards in Haskell: http://en.wikibooks.org/wiki/Haskell/Control_structures

comment 14y ago · link · parent

It meshes pretty well as is. If only I could get rid of the strings and redundant arguments.

  mymap = pattern {
    '_, []' : -> []
    'f, [x, xs...]' : (f, x, xs) -> 
      [f x].concat mymap(f, xs)
  }
It shares a lot of the same splat/rest/destructuring syntax.

comment 14y ago · link · parent

You are correct. There is not a guarantee for the future, though I doubt this behavior will change for V8 (this is currently node only). If that scares you, you can use the combinator syntax (check out the readme towards the bottom). The object literal syntax is just sugar for using combinators.

edit: BTW, if you want some precedence in a major library relying on this behavior, look no further than Backbone's router, specifically the `_bindRoutes` method.

comment 14y ago · link · parent

Take a look at the next sentence: "Keep in mind, that time is measured in the single microseconds (1µs vs 3µs) to dispatch 5 calls to the same function."

So you are still looking at sub-microsecond dispatch time for a single call. If you look at benchmark/compare.js you'll see how much shorter and clearer the pattern matched function is. I doubt this will put a strain on your performance.

edit: That said, there is likely room for optimizations and speed improvement. It will naturally take longer because it has the overhead of making function calls to the various pattern functions to check if there's a match, instead of having it all inlined like in the hand optimized function.

edit2: Sorry, this was in response to another comment that looks like it got deleted while I was editing. Now its attached itself elsewhere.

comment 14y ago · link · parent

Pattern matching is common in functional languages like Haskell or Scala. It's like a form of overloading on steroids, letting you inspect the values and structure of the arguments passed to your function (with a very terse syntax), and do different things based on that criteria. It can also take care of a lot of boilerplate like splitting an array into different parts or extracting values from a configuration object.

17.

Show HN: Matches.js -- Powerful Pattern Matching for Javascript(github.com ↗)

96 points · by natefaubion · 14y ago · 20 comments

18.

Child view event delegation for Backbone(github.com ↗)

1 points · by natefaubion · 14y ago · discuss

comment 14y ago · link · parent

I don't think so. It's not like it really does things for you or abstracts away the weirdness of CSS like jQuery does for JS. You can't write a functioning website without knowing all the quirks of CSS rendering. The only thing it's done for me is change my muscle memory. I write stylus code without the braces, colons, and semicolons so I often write syntactically wrong CSS on the first pass whenever I'm in an environment without Stylus.

comment 14y ago · link · parent

Might I also suggest nib, and excellent set of Stylus extensions for working with CSS3. One of the most useful features is image inlining, especially for gradients. While they end up being a fixed size, they also work crossbrowser (at least with any browser that supports data URIs).

http://visionmedia.github.com/nib/ http://learnboost.github.com/stylus/

All the examples show how to integrate it within your Node project, but you can just as easily use it from the command like with the `u` flag.

  stylus -u nib <file>