« first day (645 days earlier)      last day (4295 days later) » 

8:00 PM
runState takes the state computation as the first argument, initial state as the second, and returns final result and final state.
@FredOverflow ideone.com/mB7Q2
> main
1
4
Here state has type Int, and computations don't return anything.
 
Where do get and put come from?
 
MonadState.
Here's version with computations returning something: ideone.com/Oka09
[*Main]
> main
(0,1)
(6,4)
 
Where are all the questions today?
 
State is a type that has instance in MonadState.
instance MonadState (State s), to be precise.
 
@chris You mean on so?
 
8:09 PM
Well, StateT, 'cause it's implemented as transformer, but that's not relevant.
 
@Mysticial, Yeah, C and C++ at least.
 
@chris There's a lot less traffic on the weekends.
 
instance Monad m => MonadState s (StateT s m) ghci says.
 
get :: MonadState s m => m s
put :: MonadState s m => s -> m ()
 
Less stuff needed to be done an hour from posting the question I guess.
 
8:10 PM
@CatPlusPlus hu?
 
It makes sense: get is a state computation that returns the state, put is a state computation that updates the state and returns nothing.
m here is State Int.
 
I think I finally understand monads now.
 
> A monad is just a monoid in the category of endofunctors, what's the problem?
 
I think looking at them as computations which in simplest cases act as containers is the best way.
(When the embedded computation is just "return something". Dunno if it's not more confusing to be honest.)
 
So, say I have this:
do
  name <- getLine
  putStrLn $ "Hello" ++ name
That is the same as this, right?
getLine >>= (\name -> putStrLn $ "Hello" ++ name)
 
8:19 PM
Yes.
@RadekSlupik Now try arrows. And then recursive arrows.
They can access values from the future!
 
But what if I do this, what will the same be without do-notation?
do
  name1 <- getLine
  name2 <- getLine
  putStrLn $ "Hello " ++ name1 ++ " " ++ name2
 
getLine >>= (\name1 -> getLine >>= (\name2 -> ...))
 
oh wow, I just discovered this old question:
105
Q: Throwing cats out of windows

AndrewFImagine you're in a tall building with a cat. The cat can survive a fall out of a low story window, but will die if thrown from a high floor. How can you figure out the longest drop that the cat can survive, using the least number of attempts? Obviously, if you only have one cat, then you can on...

 
Good one
 
@CatPlusPlus Ah of course. Nested lambdas can still access arguments to parent lambdas, right?
That's nice.
 
8:23 PM
I liked the one about throwing fat people out of plane better.
 
So those functions (getLine 1, getLine 2 and putStrLn) are guaranteed to be executed in order?
 
@CatPlusPlus Or getLine >>= putStrLn . ("Hello" ++), right? :)
 
@RadekSlupik They cannot be executed in any other way. That's the property of >>= and nesting things in that way.
 
@RadekSlupik the magic of closures
 
So, a monad allows you to do things in order?
 
8:24 PM
Yes.
 
How would I/O work otherwise?
 
That's cool.
@FredOverflow I don't know. :P
Not.
 
Well, it could be done with something that's not monad (just by nesting functions like that), I think, but monad has laws to ensure that everything works in a sane way.
Haskellers love their typeclass laws.
> From the perspective of a Haskell programmer, however, it is best to think of a monad as an abstract datatype of actions.
 
main = do
    putStrLn "Hi"
    foo <- getLine
    putStrLn foo
-- type of main will be IO ()?
 
8:27 PM
@Cat What still confuses me about runState :: s -> (a, s) is that the function only needs the state as input, but delivers a result and a state. Why doesn't it need a previous result as an input as well?
 
That is, return IO without any other value?
 
putStrLn is String -> IO ().
Type of do block is the type of the last expression.
Well, return type of last expression.
That's how things line up.
 
And getLine is IO (String)? Or IO String?
 
getLine :: IO String
 
@FredOverflow There's no previous result.
 
8:28 PM
Oh wait IO String, yes.
 
@RadekSlupik Those two are the same thing.
@FredOverflow runState initiates the computation.
 
Oh. 3:
 
You can pass arguments to the function by currying with no problem, but there's no previous result.
 
runState initial is a pair including the a, though... does >>= simply throw the a away and only use the s?
 
sbi
8:30 PM
@Mysticial Yeah, give it to me!
 
runState computation initial returns the final result and final state.
 
sbi
Also, hello.
 
computation is State s a, initial is s.
 
sbi
@JerryCoffin That was her, saying this. It was somewhat of a joke.
 
How does IO do side-effects then?
 
8:31 PM
Remember that State s is m, and in m a the a is result of the computation. runState unwraps the computation after executing it, so it can return a.
@RadekSlupik Compiler magic.
 
And what would happen if getLine fails for some reason?
 
IO has exceptions.
 
@CatPlusPlus oh, that sounds somewhat nasty.
 
It's a black box.
 
@CatPlusPlus Oh, so you did flip the arguments by accident earlier?
 
8:32 PM
@RadekSlupik Type system is powerful enough to keep it in check. IO acts as a tag for computations that have world-affecting side effects.
And you cannot escape IO, except for unsafe means.
 
What if I want to do my own side-effects that are not possible with Haskell? I would need to provide a C API and use that then, right?
 
Depends on what side-effects you want.
 
Say OpenGL.
 
Monadic actions involve side effects by design.
OpenGL usually just runs in IO.
 
8:34 PM
@FredOverflow Yes.
 
@RadekSlupik You can wrap C functions calls in IO via FFI iirc.
 
So basically everything that has side-effects is in IO?
 
The trick is to write as much as possible outside of IO, because lifting pure functions into IO is pretty trivial.
But you can't use IO functions from pure code.
@RadekSlupik Not necessarily. Anything that has global state, I think so.
 
sbi
@R.MartinhoFernandes Never believe you get away with saying something like this while I'm away.
 
IO has nice machinery for dealing with global state, so why not just use it.
 
8:36 PM
global state is teh evilz
 
But in Haskell, you have a guarantee that pure code won't access global state.
A function from string to int cannot possibly read or modify global state.
 
There are three black box monads I can think of right now.
IO, STM and ST.
 
sbi
@keith.layne Well, I am here now. Where are you?
 
What is a black box monad?
 
One that's implemented by magic in the compiler.
Implementation of those three is not exposed.
Implementing State is trivial without compiler support. IO or ST, impossible.
 
sbi
8:38 PM
@keith.layne From a distance.
 
@Cat Is IO a special case/related to the State monad?
 
Er, no.
 
oof, I'm tired
 
IO is IO. The real world monad.
 
spent most of the day proofreading a friend's masters thesis
 
sbi
8:39 PM
@sehe What is this?
 
@CatPlusPlus Because I remember Simon PJ saying that an IO computation is a function of type world -> (a, world) and that looks pretty similar to runState :: s -> (a, s).
@jalf What topic, how many pages?
 
sbi

Haskell

concatMap = ((.).(.)) concat map
#justsaying
 
Well, yeah, conceptually it's something like this. But in reality it involves mutable things, so it's not really that.
@sbi Fiine.
 
@FredOverflow 85 pages, about international terrorism
 
sbi
room topic changed to Lounge<C++>: Hello, this is a C++ room. [c++] [c++11] [c++-faq] [fun]
 
8:40 PM
hey, I'm enjoying the haskell chatter
 
Let's go and save Haskell room from extinction. Again.
 
sbi

Haskell

concatMap = ((.).(.)) concat map
 
also I figure if people talk about monads around me long enough, I might eventually figure them out
 
sbi
@jalf I have long since given up on them.
If you cannot explain a concept in a few well-chosen sentences, it might not be all that good a concept.
 
8:42 PM
I'm pretty sure the concept is sound. But whenever I try to figure it out, people try explaining in terms of metaphors, effectively throwing away the thing I'm trying to understand
 
@sbi They're types that have three operations that follow three simple laws, really. That's about it.
 
@sbi The problem with monads is that they can be used to abstract from pretty much anything, as far as I can tell. So there is no easy way to explain them.
 
Anyway, I guess I should just spend some time with haskell when I have time. That's probably the easiest way to get an intuitive understanding
 
@sbi When virtual functions were new in C++, Bjarne Stroustrup could not convince anybody that they were a good idea. I'm pretty sure he tried hard.
 
Evening lounge
 
8:45 PM
/me pushes that onto the infinitely large queue of "stuff I want to do but don't currently have the time for"
 
@FredOverflow: sorry, no dice, there's nothing I found that does what you're talking about.
 
sbi
@CatPlusPlus Your explanation says nothing at all. In that, it's not wrong, at least.
 
@nightcracker Dice? What are you talking about?
 
@sbi Well, it's much less profound as people paint it.
 
@CatPlusPlus That's nice, thanks. :)
 
8:46 PM
@FredOverflow: "no dice" means "too bad, nothing"
@FredOverflow: the 4 parameter std::copy thing :)
 
Monads are like Linux. When their proponents try to explain why they're awesome, they get hung up on one or two trite and pointless statements, and completely forget to explain the interesting parts. ;)
 
sbi
@FredOverflow Explaining the raison d'etre of virtual functions to C++/programming newbies at a certain level takes about 15mins for me.
 
I’m going to write some code in Haskell at work to troll my colleagues.
 
@Cat In C++, when a member function calls another member function on the same object, they have access to the same state (because technically, a this pointer is passed around). Isn't this exactly the State monad, only with a different syntax and less mathematics? :)
 
sbi
@CatPlusPlus I think I can help you with that...
 
8:50 PM
@FredOverflow Yeah, maybe, somewhat.
 
@sbi How do you do it? Do you simply talk about geometric figures, or do you show how ugly C++ code would look without virtual functions?
 
sbi
Now you should have company there.
 
Xeo
lol
 
lol
 
sbi
lol
 
8:53 PM
room topic changed to Lounge<C++>: sbi breathes new life into the Haskell room [c++] [c++11] [c++-faq] [fun]
@jalf A master's thesis is written after how many semesters total?
 
@FredOverflow: 3-4 usually
 
@nightcracker No I mean how many semesters have you studied in total? There's a bachelor before that, right?
 
Me? 0 semesters
You usually do a 2-3 year bachelor and a 1-2 year master
at least in my country
 
@sbi Some people wanted to know whether their user Ids were primes
 
9:01 PM
@FredOverflow 5 years here (or well, after 4.5 years, I guess. 10th semester then?)
 
I ran an analysis on the first 100 pages of 'most active' chat users to find out more :)
@Mysticial Happy piapproximationday.com
 
@sbi right where I always am.
 
@sehe I didn't even know that existed. :)
 
@Mysticial Me neither. All hail twitter for useless trivia
 
On that note, I should probably stop reading about baby bunnies and get back to reading my paper on hypercube algorithms...
 
9:03 PM
@sbi I'm so afraid you will be slogging through endless rants and fights about singletons and shared pointers. We've missed you :)
 
sbi
@sehe Oh. I see.
@keith.layne I don't know where you always are.
 
@sbi Yeah, you definitely missed out on that... :(
 
@NikiC Ugly, in that it can surprise. Ugly also, in that it might be impossible to prevent looking up unwanted overloads if you're not careful.
 
@sehe I missed the shared pointer discussion. What about them?
 
sbi
@sehe I skipped over that. (And thanks for such a nice message! I had visitors, and generally spent the nights chatting away until 3am — but offline. Had a great time, and little incentive to turn on my machine.)
 
9:09 PM
@FredOverflow Alf thinks they're 'lobotomized' but he couldn't quite explain in what sense (to me and several others)
@sbi Oh good. Those are the best reasons to be missed :)
 
@jalf Tried Eric's attempt at explanation? (It's C#-based, so it requires no Haskell way of thinking).
 
@NikiC in practice, though, this always does exactly what you mean, and the only people who have to watch out for these cases are library writers, and especially library writers that use free functions by common names (i.e. modern style OO/multi paradigm libraries).
@NikiC There is a technique to be used ('ADL barrier') which basically means introducing a 'DMZ' namespace to avoid spurious lookups (if I recall correctly). It's one of these things that library writers deal with (besides writing funny variable names like __a and __b to avoid running into user defined macro conflicts and other C heritage)
 
That last one is for standard library writers only.
 
Writing C++ libraries sounds like a lot of fun :D
 
sbi
@sehe Yeah, really. A very distant cousin of mine, which I had previously only known by name, visited with one of her kids. The boy and my kids got along splendidly. We got even the smaller kids to sleep until 9am (by putting them to bed at insane times). We spent the nights emptying untold numbers of bottles while talking, spend the days exploring the vicinity or hanging out in my garden, and generally had a great time. Too bad it's already over.
 
9:14 PM
Novice programmer: Let's see, I need a name that no one else will have...I know! I'll use two underscores!
Happens way too often.
 
"I saw it in the standard library!"
 
"It must be the right way."
 
@NikiC It's actually more fun that writing programs, because you don't have to deal with build systems and crap.
You leave that for other people to worry about.
 
@sbi Oh nice. Yeah, our oldest didn't wake up before 9am this morning. We didn't even make it way late. Tonight, we came home at 21:00 ... from visiting grandma so... let's see what happens tomorrow. Starting now we'll all be having summer leave so let the unwinding begin
 
I much prefer writing libraries.
 
9:16 PM
@jalf As far as I'm aware, it's basically regular functions which are "tagged" that have special meaning to the compiler or can perform compile-time transformations.
 
In any language.
 
Evening gents
 
@R.MartinhoFernandes guilty as charged :) I did this, in 1992 (?) I think. That code might still be in use. Pretty sure it is
 
@ManofOneWay Is that He-man?
 
@R.MartinhoFernandes It sure is
 
9:18 PM
Can't you just use three underscores and be safe? ;)
 
sbi
@sehe Always takes the smaller kids plenty of time to move their sleeping cycle so that they wake up later. Moving it back at the end of a holiday is easier, because you just wake them up earlier, and they'll fall asleep earlier the next night. But making the sleep longer is hard.
 
All the cool animals are taken so I'm choosing a super hero instead
 
@sbi Ah. It helps summer vacation started two weeks ago for the kids.
@ManofOneWay I'm the only cool animal, right?
5
 
sbi
@FredOverflow That's like asking, because it's not safe to drink two bottles of whiskey all by yourself on one night, whether it would help to have three instead.
 
@sehe Har har.
 
9:19 PM
Do it!
 
sbi
@sehe It's started 4 weeks ago here.
 
@sbi Only now starting to enjoy the weather, too, I guess?
 
sbi
@sehe It was bad most of this week, but we didn't care much. The forecast surprisingly turned around a few days ago and now predicts 30°C next week.
@ManofOneWay I do have a few spare ones, if you want.
 
Well thank you. But I'm sticking with Heman. Besides, he and Scott Meyers have very similar haircuts.
I don't deserve the be the owl.
 
@ManofOneWay Duh. They're the same person :)
May 30 at 19:07, by FredOverflow
Jan 10 at 21:08, by FredOverflow
user image
 
9:32 PM
Hey guys, I'd like to ask something without doing any kind of research beforehand, because someone ought to know this...
 
@sehe So something bad comes out of knowing too much C++. His posture has collapsed
 
Google might.
 
@basic6 Fire away. Prepare to be scolded if it was a google-able offense :)
@ManofOneWay He needed to peer to discern the image on that tiny CRT
 
I have subclassed QAbstractTableModel and QTabelView and I'd like to allow multi-line text to be displayed to and entered by the user
There should be some simple flag to set, I just don't know which one...
 
@basic6 That's a splendid question for Stack Overflow, not the lounge
 
9:35 PM
Reading documentation might help, too.
 
inb4 meta.stackoverflow.com/questions/86997/…. Erm appears no, he has enough valid questions. So, by all means post at Stack Overflow!
afk
 
Hm, okay maybe stackoverflow is a better place for this qquestion...
 
sbi
@ManofOneWay I wouldn't be too proud of my haircut if I shared it with Scott Meyers. He isn't himself, after all:
> My hair style calls into immediate question all my judgements. — Scott Meyers
 
Thanks anyway
Oh, talking about hair styles, I'm outta here...
2
 
SO is a better place for all questions. Except those that don't fit on SO but on other sites.
 
9:40 PM
What's a documentation?
 
Also, iterators suck. Not being able to tell if an iterator by itself is dereferenceable is so annoying.
 
wats a gramer?!?
 
Ell
hi guys
 
@R.MartinhoFernandes what iterators aren't dereferenceable?
 
@keith.layne End iterators.
Quite common, the suckers.
 
9:42 PM
Invalid ones.
 
oh yeah, that was awesome of me.
I mean, you can dereference them...
But I make no promises about what happens next.
 
sbi
@R.MartinhoFernandes What does it mean for an iterator to be dereferencable by itself?
 
@sbi You can't tell without having another one.
 
How would it be possible to automatically know which iterators that are deferenceable without decreasing performance? It would have to checked at runtime for every iterator or something?
 
And that means I have to lug around four iterators instead of two. And that means I'll have to lug around eight iterators instead of two when I build the next level on top of this.
 
9:45 PM
yeah, I think some debug iterators throw on deref if they're not valid/whatever
 
sbi
@R.MartinhoFernandes Shrug. Iterators come in pairs in C++. That's unnecessary clutter, but it also is the way it is. Except for std::advance(), it makes no sense to have an iterator by itself. You always have two of them. So where's the problem?
 
Would you close this as a dupe of pointers vs references? The information's all there, but as a subset of the other question.
 
@sbi Yes, but you implement them alone.
That's what is annoying me.
 
sbi
I don't understand. (I am not implementing iterators alone tonight, I am drinking beer alone, though, if that might help.)
 
Alone iterators sad iterators.
 
sbi
9:48 PM
Alone drinkers, happy drinkers.
 
@sbi Basically, each of these wrapper iterators I'm implementing needs a pair of the underlying ones.
And that means a pair of these is four of the underlying ones.
 
@sbi No, that's alcoholism.
 
sbi
@CatPlusPlus And it's not alcoholism when you're drowning your brain in company, and/or unhappy?
 
Depends. It's definitely more fun.
 
sbi
@R.MartinhoFernandes Uh, tough luck. But also, the underlying "iterators are always times two in number" still applies, even recursively. :-/
 
9:51 PM
@CatPlusPlus After a few drinks, everything is more fun.
 
sbi
@CatPlusPlus You speak of drinking like a blind man of colors. How can drinking unhappily be more fun?
 
In company, playing games!
 
Andrei's ranges would require linear storage, not exponential.
 
Have you guys tried D programming language?
 
Yes.
No, we didn't like it.
I have deja vu now.
 
9:54 PM
What was bad about it?
 
Tools.
 
As in compilers and IDEs?
 
sbi
@ManofOneWay No, as in "hammer and tongues".
SCNR.
 
But that's not really the language now is it
 
@ManofOneWay To be honest, it lacks something with a punch.
 
9:56 PM
It stops me from using the language.
Also I don't find anything interesting in the language, anyway.
 
It has a few interesting features, but it has some annoying features, and none of the interesting features is interesting enough to make me use it.
 
sbi
@ManofOneWay Actually, the best language to program would be the one implementing the do what I want pragma. Yeah, tool support is severely lacking for it, "but that's not really the language now, is it?"
@R.MartinhoFernandes TBH, looking at Andrei's nose, there might be some punch in D, even if we can't find it.
 
sbi
What? Have you actually seen him?
 
Of course a nice compiler and IDE greatly enhances the language, but I still don't like Java even though it has the best IDE and API's (next to C#)
 
9:59 PM
"Next to"?
WTF.
 

« first day (645 days earlier)      last day (4295 days later) »