Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

God damn Haskell

Name: Anonymous 2008-07-13 8:35


import IO

main :: IO ()
main = do
        putStr "Name: "
        n <- getLine
        putStrLn n


/prog/, why doesn't this code work? I understand laziness, so "n" won't be evaluated until it's needed in "putStrLn", but why does "n" get evaluated, then "putStr" and "putStrLn" get evaulated?

tl;dr How the hell do you prompt for information in Haskell?

Name: Anonymous 2008-07-13 8:38

This is the output I get, by the way. The first "Hello" is the input.


Hello
Name: Hello

Name: Anonymous 2008-07-13 8:41

Java

Name: Anonymous 2008-07-13 8:41

First, no need to import IO, all the functions here are in Prelude.
Second, it works for me.
And there's no laziness here.
And use getArgs.

Name: Anonymous 2008-07-13 8:50

>>4
Hmmm. I'll provide some more info, then. I'm using GHC 6.8.2 on Arch Linux x86-64.

Name: Anonymous 2008-07-13 8:51

Huh, it seems to work with GHCi, but not when compiled.

Name: Anonymous 2008-07-13 9:00

Your problem is not caused by laziness, but by IO buffering. stdout is linebuffered by default, so it will only print something when it has a whole line in its buffer.

Put hFlush stdout after putStr "Name: " or disable buffering with hSetBuffering stdout NoBuffering.

Name: Anonymous 2008-07-13 9:14

>>7
Thanks!

Name: Anonymous 2008-07-13 9:20

fucking n00bs don't know about buffering? fail.

Name: Anonymous 2008-07-13 10:02

>>9
thats why Java is superior.

Name: Anonymous 2008-07-13 10:03

>>9
Wow, you are so cool, you said ``n00bs'' because you're superior and you said ``fail'' because we're at 4chan. I bet you have a lot of friends because of them.

Name: Anonymous 2008-07-13 10:15

>>11
Are you fucking retarded you fucking piece of shit, who the fucking flying fuck doesn't know about buffering?
Yes, I said n00bs because I'm superior. So what? I can't have friends because I'm superior to OP? Your logic is broken.

Name: Anonymous 2008-07-13 10:36

>>12
Grow up, you little shit.

Name: Anonymous 2008-07-13 10:45

>>11
YHBT

Name: Anonymous 2008-07-13 12:47

What's the matter, aren't you man enough to speak openly and not under the shroud of sage?

Name: MATHEMATICA MEME FAN 2008-07-13 12:59

I dig Mathematica.

Name: Anonymous 2008-07-13 13:00

>>13
I'm 26. Grow up? Where am I wrong?

>>15
No, I just think this topic sucks shit.

Name: Anonymous 2008-07-13 13:02

>>9-15
oh god how did this get here theyre not good with computers

Name: HMA MEME GUY 2008-07-13 13:04

>>16
I'M A SHAAAAAAAAAAAAAAAARK

Name: SNOW CRASH MEME FAN 2008-07-13 13:05

>>16
For any specific Reason?

Name: Anonymous 2008-07-13 13:06

Good. I have successfully trolled you all.

Name: Anonymous 2008-07-13 13:07

>>17
What does you age matter when you act like you're twelve?

Name: MATHEMATICA MEME FAN 2008-07-13 13:08

>>19
I would like to hax your anus with Fibonacci numbers.

In[1]:= Table[Fibonacci[n], {n, 10}]

Out[1]= {1, 1, 2, 3, 5, 8, 13, 21, 34, 55}

Name: Anonymous 2008-07-13 13:14

Your age doesn't matter on the Internet. Your life has no impact on how people perceive you here. You might lead a successful life, you might be a beggar. You're not how much money you have in the bank. You're not the car you drive. You're not the contents of your wallet. If you act like a kid, you are kid.

Grow up, kid.

Name: HMA MEME FAN 2008-07-13 13:18

>>23
You obviously did not know that I am an EXPERT MATLAB PROGRAMMER and can therefore hax your anus with my efficient numerical approximations.


function fib = fibonacci(rank)

alpha = (1 + sqrt(5))/2;
fib = round( alpha^rank / sqrt(5) );

Name: MATHEMATICA MEME FAN 2008-07-13 13:21

>>24
Wrong. The average age here is 42.

In[8]:= N[Mean[RandomSample[Range[80], 25]]]

Out[8]= 42.08

Name: Anonymous 2008-07-13 13:42

>>26
I am turing-complete. And you?


In[59]:= TuringMachine[{158751, 2, 2, {1, 1}}, {1, {{{}}, 0}}, 6]

Out[59]= {{{1, {1, 2}, {0, 0}}, {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0,
    0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0,
    0}, {0, 0, 0, 0, 0, 0}}}, {{2, {1, 1}, {0, -1}}, {{0, 1, 0, 0, 0,
    0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0,
    0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}}, {{2, {2, 2}, {1,
    0}}, {{1, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0,
    0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0,
    0}}}, {{2, {3, 3}, {2, 1}}, {{1, 1, 0, 0, 0, 0}, {0, 1, 0, 0, 0,
    0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0,
    0}, {0, 0, 0, 0, 0, 0}}}, {{2, {4, 4}, {3, 2}}, {{1, 1, 0, 0, 0,
    0}, {0, 1, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0,
    0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}}, {{2, {5, 5}, {4,
    3}}, {{1, 1, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0}, {0, 0, 1, 0, 0,
    0}, {0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0,
    0}}}, {{2, {6, 6}, {5, 4}}, {{1, 1, 0, 0, 0, 0}, {0, 1, 0, 0, 0,
    0}, {0, 0, 1, 0, 0, 0}, {0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 1,
    0}, {0, 0, 0, 0, 0, 0}}}}

In[63]:= Graphics3D[
 Cuboid /@ Position[
   Last /@ TuringMachine[{158751, 2, 2, {1, 1}}, {1,
      Table[0, {30}, {30}]}, 50], 1]]

Name: Anonymous 2008-07-13 15:28

Functional languages?

Спасибо, мне не нужно! Thank you, I do not need!

Прискорбно и отвратительно всё это.
Sad and disgusting all this.

Горите в императивном аду, а Saymonk Peyote Joints будет танцевать на вашей могиле.
Gore mandatorily hell, and Saymonk Peyote Joints will dance on your tomb.

Name: Anonymous 2008-07-13 17:46

>>9
OP here, I know about buffering, I just didn't know that GHC line-buffers stdout.

Name: Anonymous 2008-07-13 17:53

I feel kinda bad about OP having his thread ravaged by evil people :( I don't know why am I feeling like this, normally I wouldn't give a damn, but something got me this time.

Name: Anonymous 2008-07-13 17:56

>>30
Gore mandatorily hell, and Saymonk Peyote Joints will dance on your tomb.

Name: So that the room will be empty 2008-07-14 4:49

So that the room will be empty

Name: Anonymous 2008-07-14 4:49

evil people llol

Name: Anonymous 2009-03-06 8:57


The angle of the   objects we think   about and implement   the combat system   monsters with stats   items and so   life imitates art.

Name: Anonymous 2010-11-28 3:14

Don't change these.
Name: Email:
Entire Thread Thread List