Live data from Hacker News

A Year of Functional Programming

japgolly.blogspot.com.au

11–20 of 172 posts

Re: A Year of Functional Programming

#11
post #3

Would you recommend starting with Scala before Haskell if one want to learn FP?

No. Scala does some interesting things, but it adds a lot of complexity in order to interact with typical JVM code. Haskell doesn't have that kind of baggage, so at its heart it's a very very simple language (Lambda Calculus + algebraic datatypes + typeclasses). There are a bunch of extensions, but they can be mostly ignored while getting to grips with the basics. Programming in Haskell can involve a lot of unfamilia…

And yet that complex JVM interaction makes one possible way to "get toes wet" is to wrap existing lower level java processes (and libraries and things) in a larger functional wrapper. Top down. Assuming you have some experience, confidence, or sample code in java that you can use or understand in the problem domain. So rather than trying to find a way to use recursive functional definition of a factorial in your code (bottom up) it Might be possible to work top down and make the "main loop" or whatever of your java program a functional construct of some sort.

I am in no way claiming this is the best way, only way, or even a good way to learn FP concepts but it is a possible way to at least get feet wet, plus or minus your personal characteristics. It is merely an alternative to the extremely popular nearly universally pushed educational strategy of bottom up introduction of FP.

Re: A Year of Functional Programming

#12
post #3

Would you recommend starting with Scala before Haskell if one want to learn FP?

If your goal is to learn FP, Haskell is a better option, since it will really force you to think functionally in a way that 'softer' FP languages don't. With Scala there is always the temptation to do things the 'obvious' procedural way each time you get stuck on something.

Re: A Year of Functional Programming

#13
Ask HN: As somewhat of an old timer, I have a couple of questions about FP, not really worthy of creating their own thread:

1. I learned a rule (in my Pascal textbook), "avoid globals." Is FP just an embodiment of that principle?

2. I do a lot of programming involving hardware, often homemade. Hardware has state, such as whether a lamp is turned on or off. Does this just mean FP is inappropriate, or are there techniques out there that accrue the benefits of FP in systems that necessarily have state?

Re: A Year of Functional Programming

#14
post #3

Would you recommend starting with Scala before Haskell if one want to learn FP?

To jump on this bandwagon, no. From personal experience, FP concepts only clicked for me when I was forced to use them. Scala always has that imperative escape hatch; can't think of how to write this immutably? Just make it mutable and move on. And the language is huge, with a lot of OO bits you need to learn and work around.

Re: A Year of Functional Programming

#15
post #7

I used to like functional programming. Now I think that it's -- more often than not -- a solution in search of a problem. I can understand some of the things FP gets you (although those come at a cost, which I'll get to later); I'm just not so sure these are the things we need, or that FP is the best solution for them. One is code reuse: yes FP code is definitely more reusable. The problem is that the kind of code it…

[deleted]

Re: A Year of Functional Programming

#16
post #7

I used to like functional programming. Now I think that it's -- more often than not -- a solution in search of a problem. I can understand some of the things FP gets you (although those come at a cost, which I'll get to later); I'm just not so sure these are the things we need, or that FP is the best solution for them. One is code reuse: yes FP code is definitely more reusable. The problem is that the kind of code it…

I'm not sure about haskell, but in clojure the, run code, reason, run more code cycle is very much supported with the repl.

In fact I find the nature of functional code very much helps out here. With clojure, in a complicated system I can typically take any subcomponent and run it in the repl without much fuss/mocking or worrying about the state of the system. Since usually functions aren't modifying state I can rerun, modify, rerun over and over again without restarts.

Re: A Year of Functional Programming

#17
post #7

I used to like functional programming. Now I think that it's -- more often than not -- a solution in search of a problem. I can understand some of the things FP gets you (although those come at a cost, which I'll get to later); I'm just not so sure these are the things we need, or that FP is the best solution for them. One is code reuse: yes FP code is definitely more reusable. The problem is that the kind of code it…

Wow, I sure have the opposite reaction to you. Makes me wonder what kind of code you wrote. Some specific points: "One is code reuse: yes FP code is definitely more reusable. The problem is that the kind of code it enables reuse of more than OO is very small, simple loops." Combinator libraries sure are pretty useful, and they're more than small simple loops. "Writing the same 4 line method -- that could have been ab…

> Combinator libraries sure are pretty useful, and they're more than small simple loops.

Useful -- yes. Useful enough to pay the price -- IMO, no. OO is decent at code reuse, and the most effective, most important code reuse, is that of big libraries with rich functionality, which is done rather well in many programming paradigms (i.e. pure, statically typed FP has little to no advantage here).

> Very puzzled how you're using monads if they only appear 10 times in 50KLOC.

I'm not. But OO code that refactoring with monads would have saved me does not amount to much.

> I think you're referring to STM here.

I was talking about more limited transactional (or "concurrently mutable") data structures like Clojure atoms and agents, or restricted STM like Clojure's refs and in-memory DBs (general purpose STM is pretty much dead). I know Haskell explores STM. I'm just saying you can enjoy the same benefits in Clojure or even Java.

Re: A Year of Functional Programming

#18
post #3

Would you recommend starting with Scala before Haskell if one want to learn FP?

I want to add some color to the other answers saying "no". If your medium-term goal is to use FP for business problems (e.g. perhaps you are responsible for technology decisions), then the OP's path of "Scala for the Impatient" -> "Functional Programming in Scala" -> "Learn You a Haskell" will likely provide the easiest transition and expose you to "real world" solutions in FP. Learning F# will give a similar pragmatic path (although its complications are due to .NET rather than the JVM).

However, if you are interested to "learn FP", as in see what all the fuss is about, then there are more direct routes. My own recommendations are for Graham Hutton's "Programming in Haskell" and "Real World OCaml" (https://realworldocaml.org). There are many other good (albeit verbose) resources but these two are the shortest path (IMO) to understanding the "common denominator" and historical underpinnings of functional programming languages and functional programming. Dan Grossman's "Programming Languages" course at Coursera was also quite accessible and comprehensive, but I think it may be closed now.

Re: A Year of Functional Programming

#19

Ask HN: As somewhat of an old timer, I have a couple of questions about FP, not really worthy of creating their own thread: 1. I learned a rule (in my Pascal textbook), "avoid globals." Is FP just an embodiment of that principle? 2. I do a lot of programming involving hardware, often homemade. Hardware has state, such as whether a lamp is turned on or off. Does this just mean FP is inappropriate, or are there techniq…

I'm not a specialist of FP, so please take what I say with a grain of salt. Before answering your questions, here's a preliminary point:

0) The problem is that FP is not really defined anywhere, or rather, everyone has its own definition. I was wondering about the definition of FP about a month ago, and discussed it with my roommate who's a phd student in programming languages. The conclusion of this 2-hour long conversation was: well FP is kind of a fuzzy concept. The concepts of FP languages, typed languages, static languages, etc.. all tend to conflate. Some people will consider that Scheme, Python, Ruby, Scala, Haskell, OCaml, R are all FP languages. Some will say that only Haskell and OCaml really are. Whatever..

Keeping that in mind, here some attempts at answers:

1) In a very loose sense, I guess that you can say that, and to make it possible, you need some constructs in your language, the minimum requirements being higher order functions, and maybe closures. I'd say that's the minimum, but again I'm no specialist. But then if you want to push this "no globals" moto to its logical extreme, you get to a point where you can't even use a "print" function, since it has some side effects. Haskell does, and solves the problem with monads. But to have monads you need a very particular type system, which leads to the question of wether you need a type system to go FP all the way? I don't know. Someone more knowledgeable should answer that

2) I don't know about hardware. But like I said, FP can deal with state. In fact, even hardcore FP as embodied by Haskell can deal with state. It's not trivial to wrap your head around the concept, but it's worth giving it a shot.

Re: A Year of Functional Programming

#20
post #16
post #7

I used to like functional programming. Now I think that it's -- more often than not -- a solution in search of a problem. I can understand some of the things FP gets you (although those come at a cost, which I'll get to later); I'm just not so sure these are the things we need, or that FP is the best solution for them. One is code reuse: yes FP code is definitely more reusable. The problem is that the kind of code it…

I'm not sure about haskell, but in clojure the, run code, reason, run more code cycle is very much supported with the repl. In fact I find the nature of functional code very much helps out here. With clojure, in a complicated system I can typically take any subcomponent and run it in the repl without much fuss/mocking or worrying about the state of the system. Since usually functions aren't modifying state I can reru…

Oh, absolutely. But I wasn't counting Clojure as FP in my comment. There is no definition for FP, and the OP seemed to be talking about the statically typed, pure FP, of Haskell and scalaz. Clojure is certainly not that kind of FP, as it's neither statically typed nor pure.
Post reply on HN