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.
 
  • Post
  • Reply
Zombywuf
Mar 29, 2008

Janin posted:

I'm not denying that it's *possible* to write unreadable code in Haskell. Rather, I'm simply stating that properly written Haskell is more readable than properly written Python.

Type signatures, types, and especially category theory have nothing to do with it. In fact, category theory is irrelevant to 99% of Haskell programmers.

Oh hey, I've got some mutable state, and at intermediary mutations of said state I need to print bits of it to stdout. :psyduck:

Adbot
ADBOT LOVES YOU

Zombywuf
Mar 29, 2008

NotShadowStar posted:

code:
  context "when reading an invalid string" do
    subject { "xxx" }
    its(:read_ber!) { should be nil }
    it { should eq "xxx "}
  end
If you don't understand that then...

I don't understand that. Does it define a context or define a handler for a context. Is "when reading an invalid string" special or could it be anything? What the hell is subject, does it send an email in this context? What is :read_ber!? The last line suggests to be that this is defining a test, but then the name of the "context" (whatever that is) seems sheer nonsense.

If this is what clear readable code looks like in Ruby I want no part of it.

Zombywuf fucked around with this message at 12:18 on Oct 2, 2010

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy

Janin posted:

"DSL" is what Ruby people call libraries

If this is true then my god this is the biggest horror in the thread

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Zombywuf posted:

Oh hey, I've got some mutable state, and at intermediary mutations of said state I need to print bits of it to stdout. :psyduck:
Good thing Haskell makes working with mutable state easy, and can write to stdout! Boy, any language which can't do either of those must be really hard to use.

Derpes Simplex posted:

If this is true then my god this is the biggest horror in the thread
Nah it's just a joke about how Ruby people call every other library a DSL, because you can use them to write in retard-English.

Access Violation
Jul 21, 2003
Here's one I've never understood with PHP:

<?
for($i = "A"; $i < "Z"; $i++)
{
echo "$i ";
}
?>

output: A->Y

<?
for($i = "A"; $i <= "Z"; $i++)
{
echo "$i ";
}
?>

output: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA AB AC AD AE ... YZ

Yes, I know the correct way of doing this, but why does it behave this way? :confused:

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

Access Violation posted:

Here's one I've never understood with PHP:

<?
for($i = "A"; $i < "Z"; $i++)
{
echo "$i ";
}
?>

output: A->Y

<?
for($i = "A"; $i <= "Z"; $i++)
{
echo "$i ";
}
?>

output: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA AB AC AD AE ... YZ

Yes, I know the correct way of doing this, but why does it behave this way? :confused:

The first block terminates when $i is 'Z' because 'Z' is not less than 'Z'. The second block doesn't terminate when $i is 'Z' because 'Z' <= 'Z'. Incrementing the string 'Z' in php apparently produces 'AA' because, why not? The sequence continues until 'ZZ' fails to evaluate <= 'Z'.

And now that I've convinced you never to use PHP, you'll never have to worry about it again.

Vaginal Engineer
Jan 23, 2007

A A 2 3 5 8 K posted:

The first block terminates when $i is 'Z' because 'Z' is not less than 'Z'. The second block doesn't terminate when $i is 'Z' because 'Z' <= 'Z'. Incrementing the string 'Z' in php apparently produces 'AA' because, why not? The sequence continues until 'ZZ' fails to evaluate <= 'Z'.

This is the best. PHP is definitely Caligula.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

A A 2 3 5 8 K posted:

The first block terminates when $i is 'Z' because 'Z' is not less than 'Z'. The second block doesn't terminate when $i is 'Z' because 'Z' <= 'Z'. Incrementing the string 'Z' in php apparently produces 'AA' because, why not? The sequence continues until 'ZZ' fails to evaluate <= 'Z'.

And now that I've convinced you never to use PHP, you'll never have to worry about it again.

n ≰ n+1

Zombywuf
Mar 29, 2008

Janin posted:

Good thing Haskell makes working with mutable state easy, and can write to stdout! Boy, any language which can't do either of those must be really hard to use.

A language that makes it hard to do both at the same time should have been drowned at birth.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Zombywuf posted:

A language that makes it hard to do both at the same time should have been drowned at birth.
Agreed! Boy, I sure am glad Haskell is not such a language.

Zombywuf
Mar 29, 2008

Janin posted:

Agreed! Boy, I sure am glad Haskell is not such a language.

That the best you've got?

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
I don't really know what you're getting at, so yeah.

Are you implying that Haskell doesn't support mutable values? That's obviously false -- even ignoring pointers, the standard library has mutable types for various purposes (pointers, memory buffers, hash tables, mutex-protected storage, transactional storage).

Are you implying that Haskell doesn't support writing to stdout? I suppose there's a lot of weird propaganda about how academical it is, but come on, give us some credit.

If neither of these, then I'm lost about what you're trying to claim.

Zombywuf
Mar 29, 2008

Janin posted:

I don't really know what you're getting at, so yeah.

Are you implying that Haskell doesn't support mutable values? That's obviously false -- even ignoring pointers, the standard library has mutable types for various purposes (pointers, memory buffers, hash tables, mutex-protected storage, transactional storage).

Are you implying that Haskell doesn't support writing to stdout? I suppose there's a lot of weird propaganda about how academical it is, but come on, give us some credit.

If neither of these, then I'm lost about what you're trying to claim.

Both of those things, at the same time. Hint: monad combinators

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
I don't see what monads or combinators have to do with this. Combining mutable containers and output is trivial:

code:
import Data.HashTable as HashTable

main = do
        table <- HashTable.new (==) hashString
        insert table "go" 0
        toList table >>= print
        insert table "back" 1
        toList table >>= print
        insert table "to" 2
        toList table >>= print
        insert table "gbs" 3
        toList table >>= print

Zombywuf
Mar 29, 2008

Janin posted:

I don't see what monads or combinators have to do with this. Combining mutable containers and output is trivial:

code:
import Data.HashTable as HashTable

main = do
        table <- HashTable.new (==) hashString
        insert table "go" 0
        toList table >>= print
        insert table "back" 1
        toList table >>= print
        insert table "to" 2
        toList table >>= print
        insert table "gbs" 3
        toList table >>= print

Wheee, let's just give up on our abstractions and shove everything into the IO monad.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
Oh no, using IO to perform I/O? That's, like, too much IO!

I'd like to hear your suggestions on how to print to stdout without performing I/O.

e: also, I am totally going to use "the ___ monad" from now on. this function returns the maybe monad! here we iterate over the list monad!

Zombywuf
Mar 29, 2008

Janin posted:

Oh no, using IO to perform I/O? That's, like, too much IO!

I'd like to hear your suggestions on how to print to stdout without performing I/O.

Data.HashTable posted:

code:
new :: (key -> key -> Bool) -> (key -> Int32) -> IO (HashTable key val)

Oh poo poo, how did that IO get there, I am not good with type hierachies.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
Are you really complaining that a mutable data structure is marked as mutable? Really?

Zombywuf
Mar 29, 2008

Janin posted:

Are you really complaining that a mutable data structure is marked as mutable? Really?

Yerrrs, the IO monad marks data as mutable. This is why MonadState derives from it.

Do you actually know Haskell?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
If you really want to use a monad transformer or something, it doesn't look much worse. It just performs a little weird because you're not automatically strict in modifications anymore and you no longer have a guarantee of mutable state, only the strong reason to believe that the compiler will choose that particular optimization; you can't guarantee mutable structures outside of ST or IO, because that's what they're for.

code:
import Control.Monad.State
import qualified Data.Map as M

withInitialState = flip evalStateT

main = withInitialState M.empty $ do
  modify $ M.insert "go" 0
  get >>= lift . print
  modify $ M.insert "back" 1
  get >>= lift . print
  modify $ M.insert "to" 2
  get >>= lift . print
  modify $ M.insert "gbs" 3
  get >>= lift . print

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Zombywuf posted:

Yerrrs, the IO monad marks data as mutable. This is why MonadState derives from it.

Do you actually know Haskell?
I've written a few Haskell libraries; no big deal

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

ShoulderDaemon posted:

If you really want to use a monad transformer or something, it doesn't look much worse. It just performs a little weird because you're not automatically strict in modifications anymore and you no longer have a guarantee of mutable state, only the strong reason to believe that the compiler will choose that particular optimization; you can't guarantee mutable structures outside of ST or IO, because that's what they're for.

code:
...
This isn't an example of mutability; Control.Monad.State is actually just a wrapper around (\state -> (result, newState)) -style functions. IO and ST are the only types which support true mutability.

Also, if you want strict state in a transformer, use Control.Monad.State.Strict.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Janin posted:

This isn't an example of mutability; Control.Monad.State is actually just a wrapper around (\state -> (result, newState)) -style functions. IO and ST are the only types which support true mutability.

Exactly. The compiler may be able to optimize such accesses into mutation internally, but there's no guarantee it'll do so.

Zombywuf
Mar 29, 2008

Janin posted:

This isn't an example of mutability; Control.Monad.State is actually just a wrapper around (\state -> (result, newState)) -style functions. IO and ST are the only types which support true mutability.

Also, if you want strict state in a transformer, use Control.Monad.State.Strict.

So you can only have mutable state by dropping into another language?

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Zombywuf posted:

So you can only have mutable state by dropping into another language?
No, you have mutable state by using the IO and ST types.

Zombywuf
Mar 29, 2008

Janin posted:

No, you have mutable state by using the IO and ST kinds.

FTFY

IO is a monad to let you communicate with the world outside Haskell, for example with the FFI. If you are using it for mutable state alone you are simply referencing another language, not making use of Haskell's support for mutable state.

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde
Why are you all being :goonsay: over Haskell anyway? It's Haskell. You do it for a term at uni, scrape a pass in functional programming and drat well make sure you never have to apply for a job where you need to use it again in the real world.

I keep my Haskell programming book on my bookshelf as a stark reminder.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Zombywuf posted:

FTFY

IO is a monad to let you communicate with the world outside Haskell, for example with the FFI. If you are using it for mutable state alone you are simply referencing another language, not making use of Haskell's support for mutable state.
:psyboom:

Have you ever used Haskell? It's starting to seem like you've only heard about it by reading wikibooks and browsing /r/programming . The FFI isn't "outside Haskell", it's part of the standard language definition, and deals with much more than just language bindings.

By your logic, C isn't capable of mutable state or output because pointers and printf() are part of "another language".

e: also, ST and IO aren't kinds, they're types.

Milotic posted:

Why are you all being :goonsay: over Haskell anyway? It's Haskell. You do it for a term at uni, scrape a pass in functional programming and drat well make sure you never have to apply for a job where you need to use it again in the real world.

I keep my Haskell programming book on my bookshelf as a stark reminder.
My uni only taught C# and Java, which I literally never wrote a single line of past graduation. Once in the Real World, I had to learn C, Haskell, Python, and other useful languages. Sure, learning Haskell won't get you hired at some lovely 50k/year PHP farm, but that doesn't seem like a problem.

TOO SCSI FOR MY CAT fucked around with this message at 15:54 on Oct 3, 2010

shrughes
Oct 11, 2008

(call/cc call/cc)

Milotic posted:

:goonsay:

Real programmers [1] use Haskell in the real world. If you thought Haskell was something to discard after one term, well, you're a bad programmer.



[1] People doing interesting things, those who don't like languages because of Stockholm syndrome.

Janin posted:

Haskell

Haskell merely specifies how the program should change state. The state is actually changed by the compiled executable :c00lbert:.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

shrughes posted:

Haskell merely specifies how the program should change state. The state is actually changed by the compiled executable :c00lbert:.
The compiled executable merely specifies how the program should change state. The state is actually changed by the hardware :c00lbert:.

shrughes
Oct 11, 2008

(call/cc call/cc)

Janin posted:

The compiled executable merely specifies how the program should change state. The state is actually changed by the hardware :c00lbert:.

The hardware does not change any state, it's an unchanging four-dimensional object in spacetime :c00lbert:.

Contra Duck
Nov 4, 2004

#1 DAD

shrughes posted:

Real programmers

Using this phrase is a horror.

A very bad man
Mar 31, 2010

Contra Duck posted:

Using this phrase is a horror.

Agreed. Unless it's meant to be a derogatory description of the kind of people that attend Perl Monks meetings.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
People stuck in the enterprise acid mines itc

Milotic
Mar 4, 2009

9CL apologist
Slippery Tilde

shrughes posted:

Real programmers [1] use Haskell in the real world. If you thought Haskell was something to discard after one term, well, you're a bad programmer.

[1] People doing interesting things, those who don't like languages because of Stockholm syndrome.

"Real programmers" use what's on the defined strategic technology path for their company.

Also "trap sprung" etc. You chaps are easy pickings.

Opinion Haver
Apr 9, 2007

Milotic posted:


Also "trap sprung" etc.

that's not at all what this means

shrughes
Oct 11, 2008

(call/cc call/cc)

Milotic posted:

the defined strategic technology path

Spoken like a true programmer.

Opinion Haver
Apr 9, 2007

Net::CUPS loving sucks. In order to get information about a specific job, you have to call getJob, which internall calls the cupsGetJobs C function to get a list of every print job that the printer knows about, then iterates over it to find the appropriate job by checking the jobid. Now, to be fair, this isn't its fault, since CUPS doesn't provide any 'tell me about job N'. What is its fault is that a: there's no sign at all that getJob has this kind of behavior, and b: there's no 'get all jobs'/'get all queued jobs' function, which would be trivial to write using the CUPS API. Instead, you have to call getJobs, which returns the appropriate list of job IDs, then loop over it. Which will wind up being O(n^2) in the number of jobs in the print queue for something that should be an O(n) operation.

CUPS itself is lovely; there are functions called cupsGetJobs and cupsGetJobs2, the only difference being that the latter forces you to specify which server to get jobs from. There's also cupsGetPPD, cupsGetPPD2, and cupsGetPPD3, which perform related but different operations. Want a way to remember which does what? Too bad.

Opinion Haver fucked around with this message at 08:21 on Oct 4, 2010

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

Janin posted:

Sure, learning Haskell won't get you hired at some lovely 50k/year PHP farm, but that doesn't seem like a problem.

This one struck me right in the ego. I'll have you know that I'm a real programmer

Adbot
ADBOT LOVES YOU

Bozart
Oct 28, 2006

Give me the finger.

Smugdog Millionaire posted:

This one struck me right in the ego. I'll have you know that I'm a real programmer

I'll have you know that I'm a fictional programmer!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply