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
QuantumNinja
Mar 8, 2013

Trust me.
I pretend to be a ninja.

Puella Magissima posted:

Whoa, that's way better than what I had. I don't think it even occurred to me to recurse to the correct list instead of manually indexing, but when you put it like that it makes total sense. I guess I'm still not used to thinking functionally. I probably should have come here before spending an hour banging my head against the wall coming up with my lovely solution. Thanks a lot for your help. I'll look into Data.Map as well.

gonatic io is 100% spot-on about your learning process! Maybe try some of SICP in it, or Project Euler.

Another thing that can help with Haskell is HLint, which will give you suggestions for your code. Vim's Syntastic supports it and certainly made me a better Haskell programmer.

Also, pedantry: one recurs to the correct list, just as one incurs debt. Recursing is an unfortunate thing that happens after you've un-cursed an object and then sat, unlucky, on a throne in Nethack :v:

Adbot
ADBOT LOVES YOU

gonadic io
Feb 16, 2011

>>=
If we're being pedantic, then getGraphFromFile is a bad name and it should be called getGraphFromString. No files are involved at this stage. :colbert:

gonadic io fucked around with this message at 08:42 on Mar 14, 2016

dirby
Sep 21, 2004


Helping goons with math

QuantumNinja posted:

Another thing that can help with Haskell is HLint, which will give you suggestions for your code. Vim's Syntastic supports it and certainly made me a better Haskell programmer.
I have a related question, and keep in mind that I don't do a lot of programming. Basically, I loved the HLint-integrated environment that fpcomplete.com had until 2016 when they got rid of it. I would be willing to pay money to get something like it again.

I've never used Vim or Emacs before, is "Vim's Syntastic" the next closest I'd be able to get to that functionality? Looking at YouTube it seems like it's kinda close but would be a pain since I don't already use Vim and its keyboard shortcuts.

gonadic io
Feb 16, 2011

>>=
If you don't want to learn a whole new set of keyboard bindings, both atom and sublime text 3 have hlint packages.

Magissima
Apr 15, 2013

I'd like to introduce you to some of the most special of our rocks and minerals.
Soiled Meat

gonadic io posted:

If we're being pedantic, then getGraphFromFile is a bad name and it should be called getGraphFromString. No files are involved at this stage. :colbert:

It was indeed originally FilePath -> IO [[Int]] but I didn't change the name when I moved the file access to main :effort:

Also I tried out HLint and it seems pretty helpful, thanks for the recommendation.

Walh Hara
May 11, 2012
Holy poo poo, why is installing haskell stuff so difficult? Is it because I'm using windows?

Installing haskell platform iself was no problem. My code compiles and I can test it just fine. However, when I decided to look for a good haskell IDE (with hlint support etc) the troubles began. First try was eclipseFP. No luck, I can install eclipse and eclipseFP just fine, but cabal install buildwrapper fails. Googled a bit, found other people with the same issue but no fix. Seems weird there's a bug in such a library, but hey, poo poo happens. So I decided to look for another IDE, this time I tried Leksah. I download leksah from the website and install it, but when I try to run my script things get messy and I see error messages in the leksah cmd. Turns out cabal install cairo fails, meaning cabal also can't install gtk3h meaning it can't run leksah properly. What the heck. I've again been looking for a solution, gtk3 seems pretty import anyway, Plenty of other users with the same problem This time there were some very vague and complicated solutions as well, so I've just wasted a hour manually installing mingw (again), msys, gtk (multiple ways, including via msys), cairo (again via msys) and looking at path variables and no luck. I also completely uninstalled haskell and did a clean new install. No improvement.

Really, installing things should not be this difficult nor give so many errors. Especially the install guidelines for gtk are ridiculously complicated. Apparantly there used to be a simple installer you could use, but for some reason they thought that was too convenient.


Buildwrapper error:

src\Language\Haskell\BuildWrapper\Cabal.hs:768:47:
Couldn't match type `ModuleName' with `ExposedModule'
Expected type: [ExposedModule]
Actual type: [ModuleName]
In the second argument of `(++)', namely `hms'
In the second argument of `map', namely `(ems ++ hms)'
cabal.exe: Error: some packages failed to install:
buildwrapper-0.9.1 failed during the building phase. The exception was:
ExitFailure 1


Cairo error:

Configuring cairo-0.13.1.1...
setup.exe: Missing dependencies on foreign libraries:
* Missing C libraries: z, cairo
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they are.
cabal.exe: Error: some packages failed to install:
cairo-0.13.1.1 failed during the configure step. The exception was:
ExitFailure 1

Walh Hara fucked around with this message at 23:00 on Mar 14, 2016

KaneTW
Dec 2, 2011

That buildwrapper error seems like a bug in the module or its version bounds. Building stuff with C libraries is a gigantic pain on Windows.

Leksah starts and editing works fine, but I can't get it to (didn't bother too much) actually build packages, so I just keep a MSYS shell open and build with stack.

http://darcs.net/Windows has steps on how to build libcurl bindings and you adapt those for zlib/cairo, but honestly it's not worth the trouble. Boot up a Linux VM and call it a day.

Alternatively, you can try getting Emacs or something to work. Probably better chance since you can build ghc-mod etc. easily on Windows.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today
The Haskell Platform is pretty much deprecated in favor of Stack, FYI. It keeps things isolated and is generally a huge boon to reliability. The GTK bindings are kind of broken on Windows, and I don't think Leksah (or EclipseFP for that matter) is really very well supported in general; most people just use one of the major editors like Emacs or Sublime or Atom.

QuantumNinja
Mar 8, 2013

Trust me.
I pretend to be a ninja.
You could always install a linux virtual machine and develop haskell on that. :v:

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
My coworker uses Emacs with the Haskell thingy and it seems to work pretty well. I wouldn't call it an IDE per se, but it has syntax highlighting, indentation, and some options for quickly executing your code.

Then again, you'd have to use Emacs.

hannibal
Jul 27, 2001

[img-planes]

Ralith posted:

The Haskell Platform is pretty much deprecated in favor of Stack, FYI. It keeps things isolated and is generally a huge boon to reliability. The GTK bindings are kind of broken on Windows, and I don't think Leksah (or EclipseFP for that matter) is really very well supported in general; most people just use one of the major editors like Emacs or Sublime or Atom.

EclipseFP is dead, the main guy stopped working on it. If Emacs is too much I'd go with Sublime, Atom or VSCode.

Also I thought the platform was using stack internally now? There was a big debate about it a few months back.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

hannibal posted:

EclipseFP is dead, the main guy stopped working on it. If Emacs is too much I'd go with Sublime, Atom or VSCode.

Also I thought the platform was using stack internally now? There was a big debate about it a few months back.
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.

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.

9-Volt Assault
Jan 27, 2007

Beter twee tetten in de hand dan tien op de vlucht.

QuantumNinja posted:

You could always install a linux virtual machine and develop haskell on that. :v:

Do this + Stack + Atom with a few Haskell plugins (ide-haskell, haskell-ghc-mod, hlint).

Walh Hara
May 11, 2012
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.

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.

Pollyanna
Mar 5, 2005

Milk's on them.


Anything that isn't CLR or game development targets Linux and OSX over Windows.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

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 think setting stuff up dev enviroments in windows, especially outside of visual studio, takes more of a learning curve because it doesn't really have a good package management system for the os itself. Setting up on mac/linux is usually a matter of just typing a couple of lines in a command prompt, whereas windows is "run this batch file oh wait it didn't work because you don't have python 2.7 or something's not on your path or you need to download some random file from microsoft off the internet or you have the wrong version of a dll" or some other horseshit.

Pollyanna
Mar 5, 2005

Milk's on them.


Larger and more active development is occurring on Linux platforms for tech focused on it, which means that not only is the ecosystem more mature, it's also more likely to be up-to-date and easy to use. Popular use trumps platform.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Walh Hara posted:

I honestly have no idea if these posts about using a Linux VM are sarcastic or not.

Neither do I, but I use a linux VM to write Rust so :shrug:

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


I work in a polyglot web development team of 100+ and we write 99% of our code in VMs (though we switched to remote ones a year and a half ago). It's not a joke, it's very good.

Check out vagrant, it has some kind of folder sharing so you can edit with any ide you want on the physical host while still having a sane environment.

QuantumNinja
Mar 8, 2013

Trust me.
I pretend to be a ninja.

Bognar posted:

Neither do I, but I use a linux VM to write Rust so :shrug:

I wasn't joking; that's how I do most of my development.

Pollyanna
Mar 5, 2005

Milk's on them.


+1 for VMs. Not having to worry about dealing with differing environments and being free to use whatever editor/IDE you want is really beneficial.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
I've been doing a lot of programming over RDP in lieu of using a VM. It's great because I can type make -j and then play video games.

Also if there's not a Visual Studio extension for whatever I'm trying to use, that's a pretty good cue to just do it on Linux instead of doing Windows rituals an unbound period of time.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
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.

dirby
Sep 21, 2004


Helping goons with math

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.

informally: "lucky is a function from Integral things to Strings."
I think this is better: "For each integral type a, there is a corresponding object called lucky which has the type of a function from things of type a to things of type String"

Someone who knows a lot about Haskell/theory can probably phrase it better/correct me.

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.

KaneTW
Dec 2, 2011

"lucky is a function from any Integral type to String" sounds good to me. Maybe "from any type that's an instance of Integral to String" but while a bit more accurate it's also a mouthful

Hughmoris
Apr 21, 2007
Let's go to the abyss!

dirby posted:

informally: "lucky is a function from Integral things to Strings."
I think this is better: "For each integral type a, there is a corresponding object called lucky which has the type of a function from things of type a to things of type String"

Someone who knows a lot about Haskell/theory can probably phrase it better/correct me.

Arcsech posted:

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.

KaneTW posted:

"lucky is a function from any Integral type to String" sounds good to me. Maybe "from any type that's an instance of Integral to String" but while a bit more accurate it's also a mouthful

Got it, thanks.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I dabble with programming as a hobby, mainly in Perl and Python. Trying my hand at functional programming with Haskell. I've read in multiple places that functional programming makes concurrency/parallel programming much easier, and that functional programming scales really well.

Could someone explain at a simpleton level why these things are easier with functional programming compared to OO/imperative languages?

Bongo Bill
Jan 17, 2012

There are a variety of reasons, but the simplest one to understand is that functional programming makes immutability explicit and traditionally either enforces or requires it. Entire classes of errors associated with parallel computation are impossible when acting on immutable data. For instances, consider the humble data race: when the data is immutable, it's meaningless to speak of ensuring that one thread can only read from a variable when another is done writing to it, and all the strategies to ensure this won't happen are unnecessary when the semantics of the language eliminate the entire concept of writing to a variable.

This is an oversimplification, of course.

VikingofRock
Aug 24, 2008




Hughmoris posted:

I dabble with programming as a hobby, mainly in Perl and Python. Trying my hand at functional programming with Haskell. I've read in multiple places that functional programming makes concurrency/parallel programming much easier, and that functional programming scales really well.

Could someone explain at a simpleton level why these things are easier with functional programming compared to OO/imperative languages?

Most fundamentally, lack of mutable state means that you don't have to worry about data races (except in things like file access), and it allows for *very* lightweight threads. Also, the more expressive syntax lets you experiment with parallelization more simply (e.g. replacing calls to `map` with calls to `parmap`).

Walh Hara
May 11, 2012
Is there a good tutorial on how to update Tree/Graph like datastructure in a convenient way in haskell?

I.e. I have a date structure with theses types:

type Edge = (String, Tree)
data Tree = Leaf | Node [Edges]

I have several functions to find a certain edge according to some criteria:

findASpecificEdgeInTheTree :: ... -> Tree -> Edge

And a function to update that edge in some way:

updateEdgeInASpecificFashion :: ... -> Edge -> Edge

How do I combine these two functions, so that I get the original tree but with a specific edge updated? If possible in a generic way so I can take any "findMeAnEdge" function and any "updateAnEdge" function and combine them. Is this even possible without me having to start compairing big subtrees?


Context is that I'm trying to implement Ukkonen's algorithm for building suffix trees in Haskell (http://stackoverflow.com/questions/9452701/ukkonens-suffix-tree-algorithm-in-plain-english/9513423#9513423). It's just for fun, I've been implementing these kinds of algorithms in both python and haskell in order to challenge myself a bit and to see how the 2 programming languages compare. In some previous algorithms it was much easier to use haskell, but here I'm kinda stuck. And I haven't figured out how I'll implement suffix links either (a node can have both an edge pointing to it and a suffix link pointing to it, how do I make sure these always point to the same thing?).

Athas
Aug 6, 2007

fuck that joker

Hughmoris posted:

I dabble with programming as a hobby, mainly in Perl and Python. Trying my hand at functional programming with Haskell. I've read in multiple places that functional programming makes concurrency/parallel programming much easier, and that functional programming scales really well.

Could someone explain at a simpleton level why these things are easier with functional programming compared to OO/imperative languages?

It is mostly bullshit, and the envisioned trivial parallelism that functional programming supposedly grants has not actually manifested itself.

In principle, functional programs (which need not be written in a functional language) are easier to parallelise, because the absence of mutable state implies the absence of shared mutable state, which is the bane of parallel programming. In a functional language such as Haskell, which has fairly mature parallel programming techniques and libraries, you can spawn concurrent threads that communicate only through message passing. Of course, you can do this in any modern language, although I suppose that in Haskell, the temptation to create just a little bit of shared mutable state ("for performance/convenience, you see") is easier to resist.

The myth of easy parallelism is a little less of a myth when it comes to implicit parallelism (or better: data parallelism), where you do not use explicit threads. A previous poster described 'parmap', which could be a 'map' operation that evaluates each element of the list in parallel. This is true and good, and if the function you are mapping with is a pure function (which it certainly is in Haskell), you are guaranteed that the entire operation is free of race conditions and similar problems. So: parallelism is indeed easy. But: the only reason you want parallelism is to get good performance, and that is still hard. Consider that 'parmap' again - sure, the runtime could launch a thread for every elements, but what if the list has ten million elements? That's a lot of threads and it will kill your performance, especially if each element is very cheap to process. So you need some sort of chunking, and not start more threads than the hardware can readily utilise. And what if there are other 'parmap's in other concurrent threads in the program? You need to control the parallelism exhibited by the entire program, not just each little component, so as not to overwhelm the machine. And of course, whilst the purity of Haskell is very convenient for parallelism, the lazy semantics are most definitely not. In fact, most parallel libraries for Haskell perform eager evaluation, because laziness is totally antithetical to efficient parallelisation.

And when you get to more exotic parallel hardware, such as GPUs, the idea of efficient parallelism being "trivial" or even "easy" falls even more apart.

Now, I do believe functional languages are easier to parallelise, especially for data-parallelism, but you still need really clever compilers and cut-down languages.

I base this on being a PhD student in functional parallel programming and actually having written a compiler for a data-parallel functional language that targets parallel hardware. It's fun. :) But it's not as easy as it's often made out to be.

Athas fucked around with this message at 10:40 on Mar 26, 2016

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today
You've got a lot of really good points here, but it isn't any kind of coincidence that Haskell is the place where transactional memory is becoming/has become conventional.

Athas
Aug 6, 2007

fuck that joker

Ralith posted:

You've got a lot of really good points here, but it isn't any kind of coincidence that Haskell is the place where transactional memory is becoming/has become conventional.

No, but transactional memory is not automatically very performant (again: parallelism is easy, efficient parallelism is not). Furthermore, another reason is probably that GHC is the most dynamic and active research compiler I know of, and run quite well by people both technically and socially competent.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


What about Erlang? I don't have any direct experience of it, but people who talk about it go on and on about millions of processes on your laptop or whatever.

Athas
Aug 6, 2007

fuck that joker

Doc Hawkins posted:

What about Erlang? I don't have any direct experience of it, but people who talk about it go on and on about millions of processes on your laptop or whatever.

That's concurrency, not parallelism. Erlang is very very good, but it's not particularly fast for computation.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

Athas posted:

No, but transactional memory is not automatically very performant (again: parallelism is easy, efficient parallelism is not). Furthermore, another reason is probably that GHC is the most dynamic and active research compiler I know of, and run quite well by people both technically and socially competent.
Sure, but for the typical case of applications where it's not necessary to squeeze every last bit of juice out of your CPU, this represents a legitimate case where it's much easier to write correct parallel code.

Adbot
ADBOT LOVES YOU

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Athas posted:

That's concurrency, not parallelism.

I'm not that ignorant, I just thought share-nothing concurrency would lend itself to parallelism too. But thank you for the answer.

  • Locked thread