Live data from Hacker News

Learn You a Haskell for Great Good (2008)

learnyouahaskell.com

81–90 of 123 posts

Re: Learn You a Haskell for Great Good (2008)

#81

Haskell is such a great language. I've been recommending this book for a while now. If you are in doubt whether you should start learning it, read this post by Jeff Bone: http://www.xent.com/pipermail/fork/Week-of-Mon-20070219/0441... After I read it, I immediately began learning Haskell. Since then, Haskell made my brain melt multiple times. But it has also enabled me to build an expression parser and analytic diffe…

The true ending to that story is when you come back to your old gal and start convincing her to get monad imports. "You'll feel just like your old self, only more functional! " You tell her. The next day you hear even your neighbor Facebook got his girl PHP to try out lambdas and type annotations.

Then you realize that Haskell has been sleeping around. A lot.

It's time to get tested.

Re: Learn You a Haskell for Great Good (2008)

#82
post #48

What is a good online reference to learn about "Monads" for beginners? Someone posted a reference here on HN sometime ago but I lost it. Edit: The book was enjoyable and a delight to read, but I started struggling to keep up from Chapter 8. as it went into Monoids and Monads, I feel like I need to read other tutorials before coming back to it.

They don't teach you number theory before they teach you addition and subtraction in primary school. Don't read the "Monad tutorials" and especially do not stop programming in Haskell until you "learn monads". Find one of the respected books, read it and do the exercises. You do not need to thoroughly understand monads in order to do some IO programming just like a violinist does not have to understand the physics of…

> Reading and writing to/from files and network sockets, etc works pretty much the same as you're used to from imperative programming languages.

I agree completely that it's not necessary (and maybe even detrimental) to learn monads to use Haskell's IO, but I think this claim is dubious. Not too many imperative languages have lazy IO and this feature can be a surprising hurdle for the Haskell beginner who is versed in other languages.

Re: Learn You a Haskell for Great Good (2008)

#83
post #44

Earlier quoted context omitted.

I'd say it's pretty good. It's hard to give advice because I learned Haskell when I already had a decent college-student understanding of C++, so Haskell added diversity to my education where C wouldn't. It's good to learn languages that are different, and languages that make different things cheap -- Haskell made defining types and also made static type checking a lot cheaper than other languages in 2005. It's also…

Nice post. I just don't get the 2005 date, given the history of ML derived languages.

Sounds to me like he was just giving the year he first learned Haskell for context. Today there are a lot more mainstream languages that similarly make static typing cheaper.

Re: Learn You a Haskell for Great Good (2008)

#84
post #21

What is a good online reference to learn about "Monads" for beginners? Someone posted a reference here on HN sometime ago but I lost it. Edit: The book was enjoyable and a delight to read, but I started struggling to keep up from Chapter 8. as it went into Monoids and Monads, I feel like I need to read other tutorials before coming back to it.

You don't need to really understand monads to use them. Not at first anyway. They're basically just containers that allow you to use side effects, hold state, etc... https://acm.wustl.edu/functional/io-monad.jpg

I'm going to make an attempt to succinctly explain monads:

A monadic data type is a container that can be mapped and flattened.

- It's a container, because it stores has an inner type, which refers to the data it contains. For example, think of the type parameter that describes the elements of a list.

- It is "mappable" in the sense that its contained type can be converted to another type by providing an operation from the first type to the second type. Imagine converting a list of strings to a list of integers, where each integer is the length of the corresponding string.

- It can be "flattened" in the sense that if its inner type is an extra nesting of the container type, it can be flattened to a just one level of the container type. For example, a list of lists of integers can be flattened to just a list of integers by concatenating the sublists.

- It seems kind of trivial to say, but there has to be a way to construct a container given one of the elements it's supposed to contain.

There are also a couple of rule these operations have to fulfill. They're kind of abstract when stated on their own, but make intuitive sense when you consider examples.

Pretty simple, huh? What's cool about it is that you can assign all sorts of metadata to the container type and semantics to the flatten operation, and you get a nice representation of a pipeline of operations, where each one depends on the all the previous steps. This is basically just imperative programming -- each step depends on the current context and can optionally mutate that context, affecting subsequent steps.

You might ask, "but isn't imperative programming what we're trying not to do?" In the most general sense with mutable state everywhere, yes. But monads give you a way to describe imperative logic in very tightly controlled contexts.

Re: Learn You a Haskell for Great Good (2008)

#85
post #61

Haskell is such a great language. I've been recommending this book for a while now. If you are in doubt whether you should start learning it, read this post by Jeff Bone: http://www.xent.com/pipermail/fork/Week-of-Mon-20070219/0441... After I read it, I immediately began learning Haskell. Since then, Haskell made my brain melt multiple times. But it has also enabled me to build an expression parser and analytic diffe…

I'm not sure if that link is NSFW or not :)

Certainly doesn't help with the perception of the tech industry as a boys club. I mean I know it may have been written in jest but I was personally cringing while reading it and figured it'd be at the very least a little alienating (at worst outright offensive) for any women who'd happen to read it. Maybe I'm being oversensitive, I just know I wouldn't write anything like that.

Re: Learn You a Haskell for Great Good (2008)

#87
post #24

Earlier quoted context omitted.

>They're basically just containers that allow you to use side effects, hold state, etc... No, that is one use for Monads. A Monad is just something that has a bind (>>=) function and a return function.

> A Monad is just something that has a bind (>>=) function and a return function. You realise that this is the most useless description ever? While I'm sure it's right, it doesn't actually mean anything. Why's it a good abstraction for doing , better than any other abstraction? If it abstracts over a gazillion different things, why not have special-purpose abstractions like other languages (and thus probably make the…

>You realise that this is the most useless description ever?

Which is perhaps why many people have a hard time understanding it. That is, however, the true definition.

>Why's it a good abstraction for doing

That depends on . I can't answer that question unless you tell me what is.

> If it abstracts over a gazillion different things, why not have special-purpose abstractions like other languages (and thus probably make the language a lot simpler to use)?

Why would a special-purpose abstraction be easier to use? If you only understand monads in terms of state, you can just use them that way.

Re: Learn You a Haskell for Great Good (2008)

#89
post #48

What is a good online reference to learn about "Monads" for beginners? Someone posted a reference here on HN sometime ago but I lost it. Edit: The book was enjoyable and a delight to read, but I started struggling to keep up from Chapter 8. as it went into Monoids and Monads, I feel like I need to read other tutorials before coming back to it.

They don't teach you number theory before they teach you addition and subtraction in primary school. Don't read the "Monad tutorials" and especially do not stop programming in Haskell until you "learn monads". Find one of the respected books, read it and do the exercises. You do not need to thoroughly understand monads in order to do some IO programming just like a violinist does not have to understand the physics of…

"I still don't know what a Monoid is."

That is surprising. They show up all over in fairly common libraries - for instance, Writer collects a monoidal value. The very simplest notion is "monoid is for things you can combine". Taken from math, a monoid is a set of things (a type) for which you have an operation (called mappend in Haskell) which you can combine associatively, where the set contains an element (mempty in Haskell) that is an identity with respect to that operation.

Some common monoids are:

    Anything list-like:
        mappend appends two lists
        mempty is the empty list

    Integers over addition (newtype Sum)
        mappend adds two integers
        mempty is zero

    Tuple of monoids:
        mappend is componentwise mappend
        mempty is (mempty, mempty)

    Functions where the domain and range are the same:
        mappend is function composition
        mempty is id

Re: Learn You a Haskell for Great Good (2008)

#90
post #24
post #21

Earlier quoted context omitted.

You don't need to really understand monads to use them. Not at first anyway. They're basically just containers that allow you to use side effects, hold state, etc... https://acm.wustl.edu/functional/io-monad.jpg

>They're basically just containers that allow you to use side effects, hold state, etc... No, that is one use for Monads. A Monad is just something that has a bind (>>=) function and a return function.

New abstractions are generally better introduced to new audiences via concrete examples that can later be generalized rather than formal abstractions that float high above our heads.

The GP's explanation of the concrete features (with simple examples!) is one of the most useful explanations of monads I've seen. It isn't complete, but as a gateway to a complete explanation it is extremely good.

Post reply on HN