Live data from Hacker News

How I Start: Haskell

howistart.org

21–30 of 61 posts

Re: How I Start: Haskell

#21
Very interesting! Is there something like this for other languages / frameworks? I'd love to see something like this for Ruby + Sintara + MySQL/PostgerSQL for writing a RESTful API setup.

Re: How I Start: Haskell

#22
post #11

Earlier quoted context omitted.

You can think of a lens as just a pointer (like in C). They're not exactly like a pointer...you can't get or modify the address that it points to. But you can get and modify the thing that it points to, which is primarily how you use pointers in C. But lenses can do things that pointers can't do. Namely, they can be composed. If you have a lens that points to a person's birth date dob :: Lens Person Date ...and a len…

[deleted]

[deleted]

Re: How I Start: Haskell

#23

Earlier quoted context omitted.

Huh? In C, if you have a function from Person* to Date* and another function from Date* to Int*, you can compose them as well, and then use the resulting function to both get and set a person's birth year. The syntax is admittedly ugly, but I don't see any asymmetry between get and set.

Yes, I was talking about plain pointers (i.e. Person*), not functions of pointers. Sure, you can do both get and set, but the simple syntax is precisely what we're going for here. Without lenses that set line would have looked like this: person { dob = (dob person) { year = 2004 } } And this is just one level of nesting. Adding more levels gets really ugly. Also, lenses make it easy to do this kind of thing in a dyna…

"Functions of pointers" do seem an in-place equivalent for simple lenses. Pointers themselves less so - you can't compose pointers, and they take zero (when getting) or one (when setting) argument whereas a lens takes one or two.

Much like traditional getters and setters, lenses can offer more functionality though - for instance, an angle can be got and set in radians or degrees.

Re: How I Start: Haskell

#24
For more practical examples like this, I highly recommend the Haskell Data Analysis Cookbook [1].

After learning the basics of Haskell, having a book chock full of practical examples of things like handling CVS files, JSON, trees, graphs, machine learning, and Haskell's outstanding support for parallel computation--is a really helpful resource. The code is extremely well written; clear, concise, and readable. The author has also put the source code on GitHub for each chapter. [2]

Afterwards, to take your skills to the next level, check out Simon Marlow's Parallel and Concurrent Programming in Haskell [3]. Simon now works at Facebook, where they're using Haskell in production [4] [5].

[1] http://www.amazon.com/Haskell-Analysis-Cookbook-Nishant-Shuk...

[2] https://github.com/BinRoot/Haskell-Data-Analysis-Cookbook

[3] http://www.amazon.com/Parallel-Concurrent-Programming-Haskel...

[4] https://code.facebook.com/posts/302060973291128/open-sourcin...

[5] http://community.haskell.org/~simonmar/papers/haxl-icfp14.pd...

Re: How I Start: Haskell

#25

Earlier quoted context omitted.

You can think of a lens as just a pointer (like in C). They're not exactly like a pointer...you can't get or modify the address that it points to. But you can get and modify the thing that it points to, which is primarily how you use pointers in C. But lenses can do things that pointers can't do. Namely, they can be composed. If you have a lens that points to a person's birth date dob :: Lens Person Date ...and a len…

Huh? In C, if you have a function from Person* to Date* and another function from Date* to Int*, you can compose them as well, and then use the resulting function to both get and set a person's birth year. The syntax is admittedly ugly, but I don't see any asymmetry between get and set.

Pointers being symmetric was the point of his analogy. The asymmetry shows up when the setter is pure, returning a new version of the record instead of mutating it (as is the case in Haskell).

A getter is simple:

    x = s.foo.bar;
As is an impure setter:

    s.foo.bar = y;
But a non-mutating setter is a bit more work:

    Foo foo2 = s.foo;
    foo2.bar = y;
    S s2 = s;
    s2.foo = foo2;

Re: How I Start: Haskell

#26
Great write up, nice dissection of a simple (but not hello world simple) app, with all the ecosystem setup, etc. Apparently he is writing a book now - looking forward to that.

I think it is very hard to understand what a "beginner" needs - I now come across tutorials that finally make a certain concept "click", however the reason might not be that that specific tutorial was great, but rather that I have already hit my head on a bunch of other tutorials and practice that "prepared me"... Howver, Chris Allen actually working on teaching Haskell to a bunch of beginners is probably a great way of understanding what helps people to 'get it' sooner.

Re: How I Start: Haskell

#27
post #2

What do you think about the lens library? I have been trying Haskell for a few weeks and this library feels strange. Also I don't really think I need the things it provides. But perhaps I just don't understand it.

Lens has some very advanced abstractions, which can lead to some very thorny error messages. I second the suggestion to stay away from it for now.

Re: How I Start: Haskell

#29

Earlier quoted context omitted.

Yes, I was talking about plain pointers (i.e. Person*), not functions of pointers. Sure, you can do both get and set, but the simple syntax is precisely what we're going for here. Without lenses that set line would have looked like this: person { dob = (dob person) { year = 2004 } } And this is just one level of nesting. Adding more levels gets really ugly. Also, lenses make it easy to do this kind of thing in a dyna…

"Functions of pointers" do seem an in-place equivalent for simple lenses. Pointers themselves less so - you can't compose pointers, and they take zero (when getting) or one (when setting) argument whereas a lens takes one or two. Much like traditional getters and setters, lenses can offer more functionality though - for instance, an angle can be got and set in radians or degrees.

Yeah, that's interesting. I chose pointers because I was looking for a simple metaphor that imperative programmers would understand easily. If you ask random C programmer how to pass a single thing to a function such that you can both get and set it, pointers are the first thing that most of them will think of.

Re: How I Start: Haskell

#30
post #14

Earlier quoted context omitted.

Not sure if you caught this, but that's what Chris Allen is linking to on this page http://new-www.haskell.org/downloads/osx Also, that app is great. Really nice that it comes with Cabal 1.20 .

Oh. IIRC, haskell.org used to point to a download of the Haskell Platform for OSX (definitely not to ghc.app at any rate), so when I saw that's where it pointed, I didn't even notice that they'd changed it.

The link for OSX points to `new-www`.haskell.org. I'm sure the old site still links to haskell platform.
Post reply on HN