|
Scaramouche posted:That said, I look at the programming I do now, day in and day out, and just don't see how FP would do it. I can bet that the stuff it can do well is pretty awesome (which, I'm guessing would involve pure math and analytics), but tweaking web layouts, database massaging, file parsing, etc. doesn't seem to fit the bill. Databases are a weak point, since binding most DB libraries is a giant pain in the rear end. If you just need to generate/run SQL you can use HDBC or HSQL, but they've not kept up with modern Haskell style and can be a bit gnarly to work with. Not sure how you'd use a programming language to tweak web layouts; if you're just want to change fonts or colors or something, you can treat Haskell like a strongly-typed Perl, but I don't see much advantage to it. ---- Miranda is one of Haskell's ancestral languages; Haskell adopted several features from it, and some of the syntax will likely be familiar. However, from reading Wikipedia, it doesn't have Haskell's support for stateful programming. Features like manual memory management, pointers, or the FFI will be new to you. The best book to read for anyone interested in Haskell as a real programming language is Real World Haskell. The Haskell community has been improving at an incredible rate, so there's a bit of adjustment needed to work with modern libraries, but the fundamental teaching is sound.
|
# ? Mar 8, 2011 02:58 |
|
|
# ? Jun 3, 2024 22:51 |
|
Janin posted:Imperative/declarative is a matter of syntax. Haskell supports both declarative (let-notation) and imperative (do-notation). I disagree, but I don't want to press this point, since it will ultimately come down to whatever dictionary definition, university text-book you read. I would point out that unfortunately the haskell.org wiki is a bit schizophrenic about whether it is an imperative language is not - saying it is in one article, then not in another. Janin posted:Any tutorial/introduction/book about Haskell that doesn't explicitly mention using it as an imperative language (as a replacement for C) is terribly incomplete. For example, I've never even heard of the book you linked as a "bible", and if it was published in 1998(!!) then it's basically worthless for all intents and purposes. I mean, gently caress, that means it was written before Haskell had modules! Throw that poo poo out. Throw that out? No way man. There was a third edition out, but I was poor at uni so couldn't afford it and the third edition was always checked out of all the libraries. I would welcome suggestions on alternatives though. I read it from time to time on the train to stretch the mind, but it could be better written. quote:If by "finance sector" you mean anyone employed by any financial company, then sure -- most of them are probably using something like COBOL or Java. But if you mean people actually involved in writing finance-related code, almost all of it will be in some sort of functional language. Whether that's ML, OCaml, Matlab, R, Haskell, doesn't really matter. That's pretty much what I mean. I wouldn't have included Matlab as a 'pure' functional language, but YMMV.
|
# ? Mar 8, 2011 03:05 |
|
Haskell is basically a fun language to learn, and a dysfunctional language to use. It's impossible to think of something where you'd decide to use Haskell for that, because it's the best choice. This is because good strictly evaluated functional programming languages exist. The only real use of laziness is to avoid petty verbosity, not increase safety. The only reason to use Haskell is because it's a statically typed language with an awesome runtime, except, oh wait, even then the fact that it's lazily evaluated ruins everything. I have of course been completely unfair to Milotic, because that's just my personality -- it took me more than a semester or two to "get" Haskell, and it took me even longer to appreciate how awful it is. And I didn't have bad books to teach it to me.
|
# ? Mar 8, 2011 03:10 |
|
Milotic posted:I would welcome suggestions on alternatives though. I read it from time to time on the train to stretch the mind, but it could be better written. Purely Functional Datastructures is a nice read and has practical uses for nonfunctional programming.
|
# ? Mar 8, 2011 03:11 |
|
Milotic posted:Throw that out? No way man. There was a third edition out, but I was poor at uni so couldn't afford it and the third edition was always checked out of all the libraries. Read this: Real World Haskell. You can buy the physical version, or download the online version for free.
|
# ? Mar 8, 2011 03:12 |
|
shrughes posted:Haskell is basically a fun language to learn, and a dysfunctional language to use. It's impossible to think of something where you'd decide to use Haskell for that, because it's the best choice. This is because good strictly evaluated functional programming languages exist. The only real use of laziness is to avoid petty verbosity, not increase safety. The only reason to use Haskell is because it's a statically typed language with an awesome runtime, except, oh wait, even then the fact that it's lazily evaluated ruins everything.
|
# ? Mar 8, 2011 03:15 |
|
Janin posted:Why on earth would you ever want a strictly evaluated language? Particularly a functional one? It seems like whenever I have to use a strict language, half of my effort is spent just getting it to stop evaluating the whole world for every little value. Um, because you want it to be obvious when your expressions are evaluated, so that you can reason about the behavior of your code particularly in the presence of side effects (which exist if your program interacts with the outside world). If you want to delay the evaluation of some expression, then you make it the body of a function, and call the function when you want the value... what's the big deal? OCaml has lazy support built in, but it's a bad default. Even Simon PJ openly admits this.
|
# ? Mar 8, 2011 03:42 |
|
JewKiller 3000 posted:Um, because you want it to be obvious when your expressions are evaluated, so that you can reason about the behavior of your code particularly in the presence of side effects (which exist if your program interacts with the outside world). If only there were a way to separate side effects from the rest of the code. We could even say that the code without side effects was "pure", and that functions guaranteed not to have side effects were called "pure functions". If only that were possible, then lazy evaluation would be useful, since it doesn't matter when your code is actually executed in the absence of side effects. But I guess that's impossible. Clearly, side effects are completely inseparable from all code. After all, without side effects our code is useless. No one could ever possibly invent a construct that allowed the language to be capable of side effects AND have pure functions. That's just insane.
|
# ? Mar 8, 2011 03:55 |
|
Ryouga Inverse posted:But I guess that's impossible. Clearly, side effects are completely inseparable from all code. After all, without side effects our code is useless. No one could ever possibly invent a construct that allowed the language to be capable of side effects AND have pure functions. That's just insane. Ahem, the downside of lazy evaluation is performance, especially the kind where you use arbitrarily large amounts of memory and start thrashing.
|
# ? Mar 8, 2011 04:37 |
|
JewKiller 3000 posted:Um, because you want it to be obvious when your expressions are evaluated, so that you can reason about the behavior of your code particularly in the presence of side effects (which exist if your program interacts with the outside world). If you want to delay the evaluation of some expression, then you make it the body of a function, and call the function when you want the value... what's the big deal? OCaml has lazy support built in, but it's a bad default. Even Simon PJ openly admits this. shrughes posted:Ahem, the downside of lazy evaluation is performance, especially the kind where you use arbitrarily large amounts of memory and start thrashing.
|
# ? Mar 8, 2011 04:46 |
|
Janin posted:It is obvious when your expressions are evaluated -- it's whenever their value is needed. When interacting with the outside world, all values are strict unless you're doing something really crazy (in which case all bets are off). No it's not very unusual, and it's not a theoretical possibility, it happened a lot for me and ShoulderDaemon was bitching about it the last time we talked about it, and the last time I checked out a Haskell web server benchmark it failed to complete the highest load because it started thrashing. Maybe you just don't try to use Haskell for sufficiently interesting or sufficiently data-intensive stuff.
|
# ? Mar 8, 2011 05:18 |
|
shrughes posted:No it's not very unusual, and it's not a theoretical possibility, it happened a lot for me and ShoulderDaemon was bitching about it the last time we talked about it, and the last time I checked out a Haskell web server benchmark it failed to complete the highest load because it started thrashing. Maybe you just don't try to use Haskell for sufficiently interesting or sufficiently data-intensive stuff. In the years I've spent working in Haskell, I have never written code that began consuming arbitrarily large space, and can count the number of small (= few hundred kB/hour) space leaks on one hand. If you are regularly writing code of which you don't understand the space and/or time performance, then you should try learning about how to use your tools.
|
# ? Mar 8, 2011 05:46 |
|
quote:Why on earth would you ever want a strictly evaluated language? Particularly a functional one? It seems like whenever I have to use a strict language, half of my effort is spent just getting it to stop evaluating the whole world for every little value. Janin posted:then you should try learning about how to use your tools. never change
|
# ? Mar 8, 2011 12:42 |
|
tef posted:never change For example, using self-populating proxy lambdas and scoped imports in Python, or procedure-local static initialization instead of global variables in C++.
|
# ? Mar 8, 2011 18:48 |
|
shrughes posted:Purely Functional Datastructures is a nice read and has practical uses for nonfunctional programming.
|
# ? Mar 8, 2011 19:00 |
|
Eggnogium posted:I was reviewing a buddy of mine's homework for an intro CS class I convinced him to take. He was asked to get a bunch of information from a '/' delimited string and store it an array. Unless there were no spaces in the file, which we all know is bad thing to assume, no String.split() would not have been to correct way to do it. Had there been spaces, he would have gotten one token and not the whole file. EDIT: Also, the way it was explained to me by a professor recently, our intro to programming class has less to do with learning a language or programming in general, but learning logic. That's why a lot of schools use Java since it's easy to learn. Tux Racer fucked around with this message at 12:19 on Mar 9, 2011 |
# ? Mar 9, 2011 12:16 |
|
Tux Racer posted:Unless there were no spaces in the file, which we all know is bad thing to assume, no String.split() would not have been to correct way to do it. Had there been spaces, he would have gotten one token and not the whole file. What? It didn't say anything about a file, it said from a '/' delimited String. Even if it was a file, you'd have to read it into a String first anyway, which has nothing to do with whether .split() works as it should.
|
# ? Mar 9, 2011 16:26 |
|
Tux Racer posted:EDIT: Also, the way it was explained to me by a professor recently, our intro to programming class has less to do with learning a language or programming in general, but learning logic. That's why a lot of schools use Java since it's easy to learn. Exactly. I'm more impressed that the dude managed to figure out a hard-coded way of doing it rather than resorting to Split(). Sure split is a great function and 99.9% of coders used to the language will use it, but using it doesn't show a grasp of the actual logic that a developer should be using for more difficult tasks. Making someone think like that to make their own algorithm is, in the long run, a much more valuable thing to learn than just following the language.
|
# ? Mar 9, 2011 18:31 |
|
Kilson posted:What? It didn't say anything about a file, it said from a '/' delimited String. Even if it was a file, you'd have to read it into a String first anyway, which has nothing to do with whether .split() works as it should. Oops, I misread. I still don't think that code is anything to scoff at. It's a fairly clean solution to a problem and the way he did it was really good.
|
# ? Mar 9, 2011 19:22 |
|
I wasn't trying to disparage it. Obviously he's just getting used to programming and the different functions that are available to the programmer from the get-go. Like I said, the code made me laugh, not cry, in part because, in my opinion, Scanner.useDelimiter() ought to be much more obscure to a novice than String.split().
|
# ? Mar 9, 2011 21:38 |
|
Eggnogium posted:I wasn't trying to disparage it. Obviously he's just getting used to programming and the different functions that are available to the programmer from the get-go. Like I said, the code made me laugh, not cry, in part because, in my opinion, Scanner.useDelimiter() ought to be much more obscure to a novice than String.split(). Nah. It was probably one of those things where he found that first, so that's what he uses. Back in high school we used StringTokenizer to do the same thing because that's what we found. I still use it even though I know about String.split() and Scanner.useDelimiter().
|
# ? Mar 10, 2011 13:13 |
|
Tux Racer posted:Nah. It was probably one of those things where he found that first, so that's what he uses. Back in high school we used StringTokenizer to do the same thing because that's what we found. I still use it even though I know about String.split() and Scanner.useDelimiter(). StringTokenizer is very backwards compatible. I even have to use it when I'm writing for certain platforms because nothing else is available.
|
# ? Mar 10, 2011 14:07 |
|
It's also a hell of a lot easier to read quoted strings with a StringTokenizer than with a Scanner.
|
# ? Mar 10, 2011 15:38 |
|
edit: Ok it's not that bad, carry on.
indulgenthipster fucked around with this message at 17:18 on Mar 10, 2011 |
# ? Mar 10, 2011 17:00 |
|
Speaking of Java, I came across a lovely quirk. I was writing an assembler for a class using Java. It didn't have to actually produce runnable object code, so we were just to throw it into a text file using raw text. In the source file that we were to run this against, my professor used tabs a lot. Along with spitting out the object program to a file, we had to print out the source in one column and the corresponding object code in the other column. So I just do a System.printf("%35-s%6s", sourceLine, objCode) in order to format it correctly. I run the program and get something like this:code:
|
# ? Mar 10, 2011 18:51 |
|
Tux Racer posted:Turns out String.format() would count a tab as one character and output that to the command line, and that would interpret a tab as a certain number of characters. Tabs are one character. I'd say that String.format() assuming a specific tab-width would be much worse.
|
# ? Mar 10, 2011 18:57 |
|
Yeah, I'm confused as to why you would expect a tab not to count as one character.
|
# ? Mar 10, 2011 19:00 |
|
Because printf is used to print out text formatted a specific way. I dunno, but I just feel like there should be some recognition of "oh this is going directly to the terminal. I should probably make sure tab isn't loving up the spacing." I agree that String.format should keep the tabs in there. I should have said printf. Also, I didn't expect it because i didn't think about it. I made the assumption that it would see a tab and think "oh that's going to gently caress this up." There also isn't anything in the printf or the String.printf listing in the API that would indicate a tab is only counted as 1 character. Yes it is a foolish assumption, but not having even an option to fill in tabs with x number of spaces seems dumb. I even tried String.replaceAll() and that didn't work. EDIT: Yeah it was kind of a foolish assumption, but I still maintain the option should be there. It's 2011. EDIT 2: Changed wording for clarity. Tux Racer fucked around with this message at 21:18 on Mar 10, 2011 |
# ? Mar 10, 2011 21:16 |
|
Since you're formatting to a fixed-length anyway, just .trim() the strings you're giving to the format string and all those problems go away, don't they?
|
# ? Mar 10, 2011 21:46 |
|
Tux: You seem rather quick to blame your tools for what seems like a really straightforward misunderstanding of how things work. Libraries shouldn't bend over backwards to keep you from forgetting that tabs are characters, too. Try to imagine the problems your suggestion would cause if you wanted to print out an actual tab. String.replaceAll() works just fine for me: code:
code:
|
# ? Mar 10, 2011 22:07 |
|
A tab is one character and you use tabs all the time to format text for output to a terminal. A tab can be defined by the viewer to be an arbitrary number of spaces; in general it's useful for formatting tables where you don't have to count the number of spaces between the columns. Every programming language in existence treats a tab as a single character because that is what a tab is.
|
# ? Mar 10, 2011 22:16 |
|
Ryouga Inverse posted:A tab can be defined by the viewer to be an arbitrary number of spaces Don't tabs mean "go to the next tab stop", and it's the tab stops that are defined as an arbitrary number of spaces apart? [/pedantry]
|
# ? Mar 10, 2011 23:18 |
|
Not treating tabs as a single character would be something that would fit in this thread.
|
# ? Mar 11, 2011 02:05 |
|
It's more of an irk than anything else, but the Scala compiler treats all tabs as eight spaces and I've got IDEA set up with 4 space tabs so all of the error messages end up pointing to the wrong spot on the line.
|
# ? Mar 11, 2011 02:39 |
|
Like I said, it was a moment of realizing that tabs are a single character and this viewed it as a single character. Yeah that's a misunderstanding of the tools. I still maintain, like I said in my previous post, that there should be an option with String.format() that would prevent this from happening. I recognize that tabs can be useful, which is why there should be some sort of option. No, String.trim() wouldn't have worked in this situation. I am recognizing that I hosed up, and I learned something from it (which is what should happen when someone fucks up), but converting a tab to spaces as to not gently caress up the formatting really isn't a huge deal. I wouldn't really call that having the API bend over backwards for me. Not realizing that it wold count the tab as one character was a bonehead move on my part. I am owning that. To my defense though, there is nothing in the API that says it formats it based on characters, not spacing.
|
# ? Mar 11, 2011 02:40 |
|
Tux Racer posted:converting a tab to spaces as to not gently caress up the formatting really isn't a huge deal So do it. Problem solved.
|
# ? Mar 11, 2011 09:16 |
|
Tux Racer posted:I still maintain, like I said in my previous post, that there should be an option with String.format() that would prevent this from happening. NO
|
# ? Mar 11, 2011 19:11 |
|
Alllll right, finally some religious discussion!
|
# ? Mar 11, 2011 20:29 |
|
I'll just leave this here.code:
|
# ? Mar 11, 2011 22:49 |
|
|
# ? Jun 3, 2024 22:51 |
|
Is the first thing that gets done to the result of that query a split on `~'?
|
# ? Mar 11, 2011 22:52 |