News for hackers. Stuff that matters.
Re:Union Types in Flow and Reason by edjroot on Monday April 23, 2018 @01:16AM (#16900693)
As someone who 1) knows a few functional programming concepts, 2) hasn't programmed extensively in a functional language, 3) would like to get productive fast (in web development), but also 4) wants a language for the long term (think general purpose, decent momentum), including for academic interests... Is there a language that fits all these requirements, or am I asking too much?

Elm is too limited, Haskell seems too convoluted, unsure about F# and OCaml, don't know about good alternatives.

I've been considering PureScript because it seems to strike a balance between features, JS interoperability and skill transferability, but I'm still a little afraid of it being unnecessarily complex for my next short-term projects.

I've only now started considering ReasonML, but am I wrong to think it's much closer to the "get productive fast" side than the "long-term investment" one? Not to mention its JS-like syntax, which I admit I have a distaste for.

Re:Union Types in Flow and Reason by ahmedalsudani on Monday April 23, 2018 @02:38AM (#16900996)
I’m going to echo the Haskell recommendations. Just get started.

I was also overwhelmed by how convoluted the language seemed but eventually used it for a project, and my opinion completely changed. Haskell is a simple, beautiful language that enjoys great tooling.

Start out by learning just enough IO and monad stuff so that you can read input and pass it to your functions. This will not take long. Then you can gradually build up your knowledge of the language by creating modules that will become more and more idiomatic with time. You will discover parametrized types, laziness, and user-defined operators. At times you will struggle with how to use the type system to achieve your goal, but through practice, you will learn how it limits you, so you will know what approach to take.

Eventually you might notice that your code could be easier to read and write, and that’s where monads come in.

Somebody in this thread also recommended Clojure, which is a fine language that I would have also recommended a few months ago—it was my go-to language for spinning up servers or doing some computation. Now that I have tried Haskell though, I feel like I might not need to use Clojure again because Haskell is much more fun. So I’d hate for someone else to miss out on the fun like I did for years because they think they have to read a 600-page treatise just to get started! It’s very far from the truth.

Re:Union Types in Flow and Reason by z1mm32m4n on Monday April 23, 2018 @01:28AM (#16900726)
Considering you mention not having programmed extensively in a functional language, I'd say you should pick a language with extensive documentation for beginners. I know you dismissed it, but many people have put a lot of time and thought into designing materials for learning Haskell. In particular, I think most people recommend the Haskell book[1].

That being said, all the choices you list (Elm, Haskell, F#, OCaml, PureScript) are solid languages with good communities. The core languages are similar enough that if you start learning one, the things you learn will transfer decently enough to all the others.

[1]: Haskell Programming from First Principles (http://haskellbook.com/)

Re:Union Types in Flow and Reason by fourthark on Monday April 23, 2018 @02:20AM (#16900936)
A 1228 page introduction to the language? Wow.
Re:Union Types in Flow and Reason by djur on Monday April 23, 2018 @03:24AM (#16901189)
It is definitely much more than an introduction. There's a lot of examples and exercises, and it goes into a lot of detail on some topics. The chapter about parser combinators is 70 pages by itself. It's only an "introduction" in the sense that it starts off assuming no Haskell experience.

In a sense, it feels like the textbook for a course combined with transcripts of the lectures... although it flows better than that, of course.

Re:Union Types in Flow and Reason by zinclozenge on Monday April 23, 2018 @10:36AM (#16903715)
There's a lot of white space.
Re:Union Types in Flow and Reason by flaie on Monday April 23, 2018 @03:34AM (#16901242)
You can check with Clojure and ClojureScript to target JS specifically. You can write your backend in Clojure and the front part in ClojureScript. Having the possibility to use the same language for both is great.

It's a mature functional language with interesting properties, it's practical, data oriented. Libraries quality are top notch, you'll find no big framework but libraries working together to achieve what you want.

Some ClojureScript libraries are awesome, for example if you're on React you have Reagent or Rum that are fantastic libraries to work with React.

OP post could be written like this in Clojure (if you want to be explicit with all the screens):

    (defn needs-cancel-button [screen]
        (case screen
            :screens/loading true
            :screens/code-entry true
            :screens/success false))
You'll notice that this is not typed but you can use Clojure spec to have some validation (this way being less explicit just returning false for the Success Screen, and true otherwise):

    (def screens #{:screens/loading :screens/code-entry :screens/success})	
    (defn needs-cancel-button 
        [screen]
        {:pre [(s/valid? screens screen)]}
        (case screen
            :screens/success false
            true))
Union types can be mimicked using spec, you'll find how here: https://lambdaisland.com/blog/25-09-2016-union-types

OCaml is also great, IMO you won't lose your time by learning these languages, you'll find some way to improve your current code

Whether you learn Clojure, OCaml, F#, Haskell, Elm or Haskell, you'll end up being a better developer.

Re:Union Types in Flow and Reason by grease on Monday April 23, 2018 @01:56AM (#16900841)
All your points (1 through 4) matched with what was looking for. I chose Clojure. It's Lispy, focuses on immutable data (but not necessarily pure functions), has a version (cljs) that compiles to javascript (if you're writing web-apps, its great to write both your front-end and backend code in one langauage). I've broadly found clojure to be a "practical" functional language to work in.

(If it helps, I'm primarily a python/js developer before picking Clojure).

Re:Union Types in Flow and Reason by fulafel on Monday April 23, 2018 @02:08AM (#16900886)
For someone coming from JS/Python, I think a major familiar property of Clojure is the dynamic nature. You can quickly try something out or iterate and it runs right away, without asking you to specify the program completely type-wise.

Clojure's data checking and testing stories are good too, with spec and the various test libs - including generative tests from specs. And of course you can share the same specs on front and back end, demonstrating a payoff of the front/back code sharing.

Re:Union Types in Flow and Reason by kreetx on Monday April 23, 2018 @01:59AM (#16900858)
The core of haskell is relatively straightforward, believe it or not -- it's just that a lot of what is blogged about is bleedong edge, either language-wise or in concepts they explain.

PureScript is pretty much haskell, it simply compiles to javascript -- wouldn't say there is much skill transferability in terms of language when coming from js, but it might make sense if you develop front-end.

Don't know about the other languages.

Re:Union Types in Flow and Reason by wereHamster on Monday April 23, 2018 @02:33AM (#16900980)
There's one huge difference between Haskell and PureScript: strictness. PureScript is strict, whereas Haskell is lazy. So be careful when you write algorithms which rely on laziness.
Re:Union Types in Flow and Reason by kreetx on Monday April 23, 2018 @03:28AM (#16901205)
Thanks! Should have added that I actually haven't really done anything serious in PureScript either.
Re:Union Types in Flow and Reason by m0meni on Monday April 23, 2018 @08:35AM (#16902797)
I went through all of the languages you mention, and OCaml/ReasonML are what you're looking for (if you want a typed FP language). More than 50% of FB messenger is written in ReasonML so it's clearly a good long term investment. If you don't like the ReasonML syntax, then you can just use OCaml because they're 100% interoperable. It's also a very practical language, which unlike the others doesn't militantly enforce purity, and lets you directly write imperative code.
Re:Union Types in Flow and Reason by e12e on Tuesday April 24, 2018 @01:43AM (#16910149)
I wanted the answer to a similar question for myself to be f#/fable - but it turned out that getting up and running on Linux with dot.net core and cli tooling was a bit convoluted.

I did manage to bundle a ~32mb hello world with dependencies/runtime (with cross-compilation, yay!) - but I couldn't get giraffe or any other server (framework) running in a reasonable amount of time. (Side-note, I'd appreciate a pointer to a f# Web server stack that works in the above scenario - something light that's appropriate to build a json-api server in).

Many tutorials appeared to be a year out of date, with wrong details - leading to code snippets not working, things not building, dependencies not installing.

Since I know ocaml is solid, I now am a strong believer in reasonml (which fixes some of the oddities with ocaml, making it more pleasant - in a way a little more like standard ml).

Reasonml has a strong Web app side, and compiles to sane js.

The other great option is clojure/clojure script. It's been dogged a bit by jvm (startup) overhead - not sure how/if graal/truffle AOT compilation will improve that.

Re:Union Types in Flow and Reason by azernik on Monday April 23, 2018 @10:48AM (#16903825)
Are you specifically looking for an introduction to functional programming, or to more generally modern language features? The strong static typing of Haskell or OCaml is orthogonal to their functional properties, but they tend to go together because they were designed by academic types in the last 20-ish years. Assuming you're interested in all of the above:

For immediate productivity, I would recommend Scala - it's run on the JVM, and lets you fall back to a fairly Java-like subset. It's ugly in some ways, but has a more mature web programming ecosystem than a lot of other functional programming languages - a decent backend framework in Play and Scala.js for maybe writing a few critical browser-side libraries - and has decent and growing adoption.

If you're not looking for quick productivity in web development, and don't care all that much about learning a language that's immediately applicable to existing job opportunities, I'd probably recommend the more "pure" modern languages like Haskell or OCaml; they're niche, but it's a stable niche, especially in more academic circles, and will give you a cleaner mental model of all the features that are hackily being tacked on in JS and Scala.

I've heard good things about Clojure (think LISP on the JVM), but haven't personally tried it and don't know how vibrant its community is. Having access to JVM libraries, as with Scala, is a great plus for immediate productivity.

Re:Union Types in Flow and Reason by thardus on Monday April 23, 2018 @02:34AM (#16900982)
The purescript example in the post shows one of Purescript’s biggest problems, and that’s non-optimal codegen.

The series of if checks (O(n)) it generates as opposed to a switch statement can really add up in loops with bigger enums.

Of the langs listed, ReasonML/OCaml have the best codegen/ffi story, it’s relatively easy to drop them into existing JS projects.

Re:Union Types in Flow and Reason by 75dvtwin on Monday April 23, 2018 @09:12AM (#16903086)
apologies for recommending to extend your scope of interest. But I would highly recommend to add to your list of 'targets': mobile development. That's because you mentioned: longterm.

Longerm, in my views, means being able to write software for web, desktop, multiple smart-phone/table platforms, with a backend in, ideally, the same language/tooling as front end.

It seems like ReasonML is the only one that is targeting the above [1] (but I could be wrong). And that's because of its integration/support of ReactNative.

[1] https://medium.com/@peterpme/your-first-reasonml-pr-into-an-...

Re:Union Types in Flow and Reason by danharaj on Monday April 23, 2018 @09:32AM (#16903221)
Haskell supports this via GHCJS and cross compilation support. One cross platform library for front-end coding is Reflex-Dom
Re:Union Types in Flow and Reason by lmm on Monday April 23, 2018 @08:21AM (#16902707)
I'd go for F#, OCaml, Scala, or possibly Rust.

Elm, Purescript and ReasonML feel like much smaller communities that I wouldn't trust to necessarily make for a good long-term investment; Haskell is a bit too much of a jump to get productive in immediately. If you learn like I do - incrementally - then you want a strictly-evaluated, mainstream-ey language that allows you to write side effects without tracking them, just to start with.

Re:Union Types in Flow and Reason by w4tson on Monday April 23, 2018 @02:06AM (#16900877)
How about Kotlin? First class support on Android. Great tooling and compiles to JS
Re:Union Types in Flow and Reason by raquo on Monday April 23, 2018 @01:46AM (#16900797)
Scala.js is a great, stable, mature tool. Scala is a sharp sword, but it fits your criteria quite well. I'm certainly enjoying Scala.js very much.