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
sarehu
Apr 20, 2007

(call/cc call/cc)
You mean ((->) r).

Adbot
ADBOT LOVES YOU

sarehu
Apr 20, 2007

(call/cc call/cc)
Category theory is a waste of time.

sarehu
Apr 20, 2007

(call/cc call/cc)
I've used both, Haskell is faster because it has good syntax, static typing, and is advanced enough that it doesn't need to resort to a macro system to do basic programming tasks.

sarehu
Apr 20, 2007

(call/cc call/cc)

Smoke_Max posted:

Hi, Haskell newbie here. I was wondering why main doesn't have a [String] -> IO () type signature like other programming languages, like C/C++ or Java. It would be pretty cool, thanks to pattern matching, to be able to do things like this:

That's a relatively arbitrary standardization of C -- main can actually take three arguments on some platforms:

code:
int main(int argc, char **argv, char **envp)
Okay, according to Wikipedia, on OS X it can take a 4th argument.

It's a trendy way to make platform-specific stuff be in a platform-specific library, instead of having it be something that's in the "language". Other languages do it this way too. In Windows the command line is actually a single string, which you'll see if you use WinMain as the entry point, and you have to call GetCommandLineW to get the Unicode version.

sarehu fucked around with this message at 00:49 on Jun 4, 2015

sarehu
Apr 20, 2007

(call/cc call/cc)

gonadic io posted:

- (^^) raises a float to an integer power.

Huh. It's a shame that they reappropriated the logical xor operator for this.

sarehu
Apr 20, 2007

(call/cc call/cc)
Yeah but those aren't short-circuiting.

sarehu
Apr 20, 2007

(call/cc call/cc)
At any rate, there are certain abstractions you just can't use with functional programming without a performance slowdown.

sarehu
Apr 20, 2007

(call/cc call/cc)
I thought Okasaki's book was an exceptionally nice book to read from cover to cover.

sarehu
Apr 20, 2007

(call/cc call/cc)
checkS takes an expression and the list of variables that are in scope. If you want to know whether a variable's in scope, see if it's in that list.

sarehu
Apr 20, 2007

(call/cc call/cc)
Well, they're saying "add it to the list," but that's speaking in functional programmer codetalk for "put it in the list you return/pass to some other function."

sarehu
Apr 20, 2007

(call/cc call/cc)
I don't know Elm but I'll bet you a zillion bucks it's that the type of "::" is a -> List a -> List a and also by the way it's probably right-associative.

flatten left returns a List a, and (value :: flatten right) evaluates to a List a.

You need to append the lists using an append function, you're trying to cons them together.

Edit: Edited to pretend more convincingly that I didn't check the Elm docs before writing parts of this reply.

sarehu
Apr 20, 2007

(call/cc call/cc)
If you're making an interesting programming language these days it's become a requirement to scare off the functional programming morons. Avoiding type classes helps them establish their market position.

sarehu
Apr 20, 2007

(call/cc call/cc)
You're finding compiler bugs but your code won't typecheck anyway.

Your general traversal strategy isn't going to work. You only have func which is of type a -> b -> b. Thus there's no way you can combine the results of (partial left) and (partial right), because they both have type b. You'd need some sort of b -> b -> b function to do that.

sarehu fucked around with this message at 20:59 on Dec 31, 2015

sarehu
Apr 20, 2007

(call/cc call/cc)
My favorite functional language is Python. It has lambdas and list comprehensions.

sarehu
Apr 20, 2007

(call/cc call/cc)

Jarl posted:

Bought the book Learn You a Haskell for Great Good. I like both the language and the book and have just finished Applicative Functors leaving only Monoids, Monads and Zippers.

The book has a few (very few) errors (thank god not in the code though),

What errors?

Jarl posted:

I get applicative functors now, but it sure took some effort. With that in mind should I prepare myself for a long haul with monoids and monads, or am I already almost there conceptually having understood applicative functors?

Monoids are very easy -- an associative operator with an identity element. For example, adding integers, multiplying integers, matrix multiplication, string concatenation. Monads are a generalization of the only sane API for constructing I/O actions in a "pure" functional manner -- and another associative law that makes sense.

sarehu
Apr 20, 2007

(call/cc call/cc)

rjmccall posted:

Local mutation has basically none of the disadvantages of shared/global mutation and eliminates a lot of local data-flow headaches. You should not feel bad about using it.

Yeah, the main benefit of functional programming is in having immutable data structures (that can be efficiently used). You can connect them together and use them more versatilely than otherwise, and are harder to screw up. It's generally a good style of software architecture.

A rather nice pure functional programming language would be a version of Rust without RefCell, Cell, or other stuff that uses UnsafeCell, that lets you freeze objects onto a garbage collected heap. So you get local mutation and build arrays and can do mutable borrows. But it would also benefit from not having horrendous "let mut _:_" bullogna and also some goto statements to scare off undesirables.

sarehu
Apr 20, 2007

(call/cc call/cc)

xtal posted:

Is local mutation necessary with sufficiently advanced COW and GC?

Depends what you're building and how important performance is? And convenience?

When some people got me to do a Goog Code Jam, I first tried using Haskell, and... ick. It's much nicer to develop code rapidly with for loops, with pushing stuff onto vectors, with being able to turn a map into a fold with a variable declaration, and without having to janitor values into and out of functions into the right kind of tuple.

But also imagine doing stuff where performance is important. In C++, people often disable copy constructors on a type for that reason that copies are too expensive, and they don't want to get one accidentally. If you're setting a vector element, it's relatively easy to have an accidental extra pointer to it. I mean, let's say it's in a variable and you're appending to it. v = push(v, x). Well, you'd need some semantic defined there that moves v into the parameter list of push and moves v out without bumping a refcount. That's what Rust has -- only instead of reasoning in your head about what the refcount should be, and hoping the code never evolves into something that has to copy, it's enforced by the language.

sarehu fucked around with this message at 01:45 on Oct 11, 2016

sarehu
Apr 20, 2007

(call/cc call/cc)

xtal posted:

With those criteria I would say that GC and mutability are two sides of one coin. If you're using immutable structures you need good GC. If your performance needs are such that you can't afford immutability, you can't afford a GC either.

Not true at all. You can benefit immensely from improving absolute performance. Not all performance requirements are low-latency/low-memory-usage. You also benefit from the convenience of mutable local variables without creeping performance risk.

Adbot
ADBOT LOVES YOU

sarehu
Apr 20, 2007

(call/cc call/cc)

Shinku ABOOKEN posted:

What *is* OTP anyway?

Outlaw Techno Psychobitch.

  • Locked thread