Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Arcsech
Aug 5, 2008

VikingofRock posted:

I don't know enough about the other functional languages to write an introduction for them, but if anyone posts some information, resources, example code, etc for other languages I will add it to this OP.
I wrote a thing for F#:


F# is a functional language descended from the SML/OCaml family and based on Microsoft's .NET platform. This allows easy interop with C# and other .NET applications & libraries, but can lead to some awkwardness as much of the .NET standard library wasn't designed with functional programming in mind. In addition to .NET interop, you get some really awesome languages features such as 1) type providers, which use data files, database connections, or even other programming languages to inform your type system and Visual Studio's autocomplete, 2) Units of Measure, which let you tag primitive types with additional type data to reflect their units and have the compiler do dimensional analysis at compile time, and 3) computation expressions which let you write code in a way similar to Haskell's do-notation, but with more flexibility (and in my opinion, a bit more readable).

F# resources:
  • Try F#: Try F# in your browser!
  • F# For Fun and Profit: A website with a thorough "Why F#?" series, well worth looking through to get a sense of what's available in F#.
  • F# Foundation: A pretty good directory of F# resources.

Some cool F# things:
  • Websharper: Write webapps in 100% F#. F# on the server, HTML combinators to generate HTML, and an F#->JS transpiler (although it can work with normal HTML templates if you so desire)
  • Visual F# Power Tools: While Visual Studio supports F# by default, it's kind of half-assed. This extension makes it a bit more fully-assed and generally improves quality of life quite a bit.

Adbot
ADBOT LOVES YOU

Arcsech
Aug 5, 2008

duck monster posted:

Might be worth throwing Racket under the lisps. Its a scheme dialect with a really cool learning UI and some great libs.

This is true. It's also the best way to get an SICP-compatible scheme (via #lang planet neil/sicp) right now.

Arcsech
Aug 5, 2008

fleshweasel posted:

I spent a lot of time with How to Design Programs in supplement to my regular college programming classes and it was incredibly helpful. It's what I recommend to everyone starting. It really strips away the stuff beginners should not be worrying about and helps beginners build good habits.

I haven't worked with the scheme book people mention often in the same breath but I'm sure it's good too.

HtDP and SICP are often mentioned together but they're really quite different in terms of approach and scope. HtDP is, I would say, appropriate for someone learning programming for the first time - it uses Racket's ability to work with images easily to make it more engaging, it introduces file IO early to make it easier to solve practical problems, and it talks about topics like testing very early as well. SICP favors more difficult algorithmic challenges and is very theory-heavy - I'd recommend it for people who already have some experience with programming to help them go back and thoroughly understand the fundamental concepts of computer science. HtDP is a book about programming, which includes a bit of computer science, while SICP is a book about computer science, which includes a little bit of programming. They're both excellent books targeting slightly different audiences.

Arcsech
Aug 5, 2008

Lumpy posted:

As someone just starting to look into functional programing, which ones are the "impure" ones? Why are they only "functional-ish"? Why should I avoid them?

"Pure" functional languages are those which force side effects (mostly you can think of this as any sort of input or output, although it's broader than that) to be reflected by the type system. Haskell is the only language that's even kinda-sorta mainstream that's purely functional, with some experimental languages like Elm, Agda, and Idris also falling in that category. A language being purely functional brings a lot of tradeoffs that can get pretty complex to explain.

Essentially, anything that's commonly described as functional will be good for learning functional programming, don't worry about it*. The only people who discount "impure" or "functional-ish" languages are basically fundamentalists.


*: However, learning a pure functional language as an intro to functional programming can be good for you as it doesn't allow you to intentionally or accidentally fall back into an imperative mode, instead forcing you to think functionally. However, as an introductory language, I'd recommend Elm - it is purely functional, but it's easy to do neat stuff with it since it runs in a browser and the author of the language puts a heavy emphasis on making it easier to learn. Elm's model of I/O is much easier to wrap your head around than Haskell's, in my opinion, which can be a major stumbling block in Haskell.

Arcsech
Aug 5, 2008

QuantumNinja posted:

Question about Elm: how would I go about making an Elm application interact with a database backend? The 'easiest' way I can imagine from the API is to use JSON to post requests to some server-side script and get the results back. Is there an approach (maybe as a library or tutorial) that doesn't require doing something like that for user login authentication?

Maybe the Firebase bindings? That's about all I know of.

Arcsech
Aug 5, 2008

Ralith posted:

Maybe, I admit I don't follow community news very closely. I think it's pretty difficult to go wrong just installing stack directly, though. The important thing is to not be using raw cabal install.

Yeah, cabal-install is hideously broken. Stack actually works, instead of breaking everything constantly.

Arcsech
Aug 5, 2008

Walh Hara posted:

I honestly have no idea if these posts about using a Linux VM are sarcastic or not. I've certainly never done such a thing and don't think it's a valid reply to the criticism of "installing a good IDE should not be so difficult".

I installed via stack now (again, horrible documentation and the installer did somehow not automatically install gci, leaving me to gusss which stack command I needed). I'm currently using Geany, it's ok. Only complaint is that it doesn't do debugging (does any haskell IDE?). I might try atom or sublime.

Most non-mainstream languages target Linux primarily, with Windows being very much a second class citizen. I use a Linux VM for development more often than not. I agree it's not a good response, but it's just the state of things.

Debugging Haskell is, last I checked, in a pretty sad state. It's a pretty hard problem to solve due to the lazy evaluation.

Arcsech
Aug 5, 2008

Hughmoris posted:

Poking around Haskell and Functional programming by reading the "Learn You A Haskell" book. In one of the earlier sections, its talking about syntax in functions. It has this example:

code:
lucky :: (Integral a) => a -> String  
lucky 7 = "LUCKY NUMBER SEVEN!"  
lucky x = "Sorry, you're out of luck, pal!" 
If I was describing this function to someone, how would I verbalize that first line? I understand what the function does but I'm not positive what " lucky :: (Integral a) => a -> String" is telling me.

I would say that as something like "From any Integral type to String." The first part in parentheses indicates that a must implement the type class Integral, then the rest reads like a normal type signature, with that restriction.

Arcsech
Aug 5, 2008

tazjin posted:

I second this. Elixir specifically is a very approachable language (Elm maybe a little less so), but the combination has been a very effective tool for lifting programmers out of the dark pit filled with Javascript and Ruby.

Elm is by far the most approachable purely functional language, and arguably one of the more approachable languages in general because the compiler errors are really, really good, which sounds silly, but given how much of learning new programming concepts is changing things and seeing what works, having the compiler explain very clearly why some things won't work and give suggestions on how to fix it is super helpful for learning.

Arcsech fucked around with this message at 21:49 on Apr 27, 2016

Arcsech
Aug 5, 2008

tekz posted:

How does elm compare to say, using react+redux, which I really like.

The architecture and thought process is similar between the two. The main difference is that Elm has a strong static type system, and encodes IO in the type system, kinda like Haskell - although it does so in a very different (and in my opinion, easier to understand) way.

Arcsech
Aug 5, 2008

VikingofRock posted:

Me too! I also liked the [1..5] syntax and back ticks. I suppose I can see the argument for removing all three though.

The [1..5] syntax was nice, but I'm not too put out by losing it. Backticks I could go either way on, I can definitely see the simplicity of just encouraging |>.

Good riddance to x' style variable names though, they're awful and don't communicate anything meaningful. But then, I also hate point-free style, so I'm somewhat out of step with a lot of Haskellers anyway.

Arcsech
Aug 5, 2008

Maluco Marinero posted:

I want to look into erlang or elixir for web development, after having a lot of experience with Python. My main usage will be building stuff bigger than the stuff I use Django for, so essentially I want to figure out the OTP stuff so I can make good use of the hardware I have with at least security in the knowledge that scaling won't be so bad as splitting up a monolith.

What's best in breed in the ecosystem according to people who actually use erlang/elixir? What am I losing if I use elixir? All the frameworks out there market themselves exactly the same way saying they have a great dev experience or fault tolerant or whatever, all products of the language largely, so it's hard to tell where's the best place to invest my time in first.

If you want to do web dev in the Erlang ecosystem, Elixir + Phoenix is almost certainly what you want, especially coming from Python. Phoenix is very user-friendly, and it's far and away got the most users and the largest community of anything on the BEAM (Erlang VM).

Programming Elixir and Programming Phoenix are both pretty good books to get started with Elixir.

The downsides of using Elixir rather than Erlang:
  • The Elixir syntax makes it feel more like your old programming language, which can make it tempting to write non-Erlangy code
  • You will want to learn to read Erlang syntax at some point anyway, because a lot of the examples on the internet are written in Erlang (all of them are still 100% relevant to Elixir though)
  • Macro overuse is a thing people warn about, but I haven't run into problems (yet)

Arcsech
Aug 5, 2008

Colonel Taint posted:

But... what's the different between 'extending the language' and building an API/library then? I've read McCarthy's paper and I realize the whole thing is built from a fairly basic foundation, which is cool in itself, but I keep getting hung up about that particular choice of words, especially when multiple authors use it to refer to defining functions. I can kind of seeing it make sense when talking about macros. Maybe I just haven't reached lisp nirvana yet.

I mean, that's basically the point: Adding new syntax is as simple as adding a library. Consider Clojure's arrow macro:
code:
(-> "a b c d" 
           .toUpperCase 
           (.replace "A" "X") 
           (.split " ") 
           first)
which expands to:
code:
(first (.split (.replace (.toUpperCase "a b c d") "A" "X") " "))
In a language like Java, a pipeline operator like that would need to be part of the language. But in Lisp, it's just a macro, so if you need more complex behavior, that's just a library. (Yes, in ML-alikes you can do this with operators, but that's just because the syntax supports automatic currying. This is just one example.)

Another good example is Clojure's core.async, which implements a concurrency model similar to Go, but with no need for language support: It's just a library. And you can do this all pretty easily and safely, because the language is written in the same data structures you use for "normal" data.

So yes, it's "just" macros, but it's really, really drat good macros.

Adbot
ADBOT LOVES YOU

Arcsech
Aug 5, 2008

Doc Hawkins posted:

That's JavaScript.

Interestingly, what became JavaScript was originally supposed to be Scheme, until Netscape decided that their scripting language had to look like Java.

Basically JavaScript is what you get if you take Scheme and gently caress it up horribly by trying to squeeze it into a Java suit over the course of 10 days

Arcsech fucked around with this message at 05:51 on May 7, 2017

  • Locked thread