_deafbeef 2017-01-30 02:47:50
oh okay merijn, thanks for the suggestions
_deafbeef 2017-01-30 02:48:31
the compilation process is pretty much equivalent in linux though, I tried the same steps in ubuntu gnome
_deafbeef 2017-01-30 02:48:42
the result of the process, I mean
zipper 2017-01-30 02:49:49
LOL why write haskell if you plan not to write type sigs? "merijn | Profpatsch: Why not just add type signatures to avoid both warnings?"
zipper 2017-01-30 02:50:11
:)
grr12314 2017-01-30 02:50:36
yo
zipper 2017-01-30 02:51:08
Profpatsch: Can't typeholes help you figure it out? Then you add whatever you get from GHC?
zipper 2017-01-30 02:51:26
grr12314: Hello
grr12314 2017-01-30 02:52:25
why it seems impossible to make a simple function that takes no args and returns an infinite list of strings read from stdin?
grr12314 2017-01-30 02:52:42
without any io traces in its return type
jophish 2017-01-30 02:52:58
grr12314: that's because reading from stdin requires IO
zipper 2017-01-30 02:53:25
"infinite list of strings read from stdin"?
grr12314 2017-01-30 02:53:27
but cant the function handle it internally and just return the list
zipper 2017-01-30 02:53:36
Like asking the user to press enter every time?
jophish 2017-01-30 02:53:48
It is possible to make this, something like: IO [String], however I'd stronly recommend to avoid this as lazy IO can be a huge headache
grr12314 2017-01-30 02:53:53
and the action happens only when you need a list item
zipper 2017-01-30 02:53:57
Like a loop for forever with getArgs?
zipper 2017-01-30 02:54:02
:t forever
lambdabot 2017-01-30 02:54:05
Applicative f => f a -> f b
zipper 2017-01-30 02:54:38
Sorry, not getArgs, getLine or whatever
zipper 2017-01-30 02:55:07
Ok idk what I'm talking about I'm going to just stfu and see what jophish says
jophish 2017-01-30 02:56:27
grr12314: the problem is that 'the action' has the type 'IO String'.
Ferdirand 2017-01-30 02:56:30
:t interact
lambdabot 2017-01-30 02:56:35
(String -> String) -> IO ()
zipper 2017-01-30 02:56:51
jophish: What did he mean by handle it internally?
grr12314 2017-01-30 02:57:12
yeah like you said zipper, like a infinite loop with getLine
grr12314 2017-01-30 02:58:02
ok im trying to wrap my head around it but i guess i'll need some actual programs before i can
zipper 2017-01-30 02:59:02
grr12314: You can write that eaily as `forever getLine`
zipper 2017-01-30 02:59:21
With an if to check for a string like stop
zipper 2017-01-30 02:59:25
"stop"
zipper 2017-01-30 02:59:36
to stop the forever
jophish 2017-01-30 02:59:47
grr12314: what do you want to do with the string you get from the line on stdin?
Ferdirand 2017-01-30 03:00:07
is lazy IO really such a huge headache, when you are reading from a pipe ?
Ferdirand 2017-01-30 03:00:21
or any non-seekable fd
grr12314 2017-01-30 03:00:28
well its more generic and theoretical question
merijn 2017-01-30 03:00:37
Ferdirand: It depends
grr12314 2017-01-30 03:00:38
i might want to takeWhile or whassname
jophish 2017-01-30 03:01:07
Ferdirand: That's probably one of the better cases for it, but there could still be problems wrt resource ownership
merijn 2017-01-30 03:01:13
jophish: I'm not quite sure what lazy IO has to do with this entire issue?
lyxia 2017-01-30 03:01:47
" and the action happens only when you need a list item" <- this is lazy IO
jophish 2017-01-30 03:01:54
merijn: grr12314 seemed to want a value with type 'IO [String]'. Where the list was an infinite list of lines from stdin
grr12314 2017-01-30 03:02:20
yeah except without the IO part, but i get its impossible
lyxia 2017-01-30 03:02:38
it's actually possible with unsafePerformIO
merijn 2017-01-30 03:02:55
lyxia: You're not helping
merijn 2017-01-30 03:03:39
Telling beginners about unsafePerformIO is about as helpful as handing handguns to toddlers, it's only going to get them hurt
lyxia 2017-01-30 03:03:51
But this is exactly what grr12314 asked.
AWizzArd 2017-01-30 03:04:04
In "Learn You A Haskell" the author said that when opening a text file in ReadMode then under the hood it is buffered line-wise. Is there a way to overwrite this default behaviour, i.e. I know that a file contains gigabyte-sized lines?
grr12314 2017-01-30 03:04:10
im just trying to understand how all that io action stuff and why it is so sticky and hard to get rid of. but i guess its just a quirk i have to get used to
merijn 2017-01-30 03:04:20
lyxia: And much like with the malevolent genie in a bottle people don't always want what they wish for
AWizzArd 2017-01-30 03:05:02
Oh okay sorry, nevermind. It's explained just in the next paragraph.
jophish 2017-01-30 03:05:05
grr12314: It's impossible to get rid of because if one could get rid of it one could write functions which appear not to deal with the outside world on the surface, but underneath launch missiles or whatever
grr12314 2017-01-30 03:05:29
i have to do some hello-world types of puzzles in haskell instead of just trying to theorize about it i guess
merijn 2017-01-30 03:05:33
grr12314: It's not so much a quirk as a foundational principle. To keep the language pure (which roughly translates to "whenever you call a function with the exact same arguments, you should get the exact same results) you can't allow side-effects, so effects must be accounted for in the type system
jophish 2017-01-30 03:05:44
what most programs do is have some "shell" on the outside which handles all the IO, and do some interesting pure computation underneath
grr12314 2017-01-30 03:06:35
yeah and a way to generic-alize that shell
merijn 2017-01-30 03:06:47
grr12314: Take 'getLine :: IO String', suppose this would be, instead 'getLine :: () -> String' and read a line from stdin, then clearly 'getLine ()' and 'getLine ()' wouldn't necessarily be the same
grr12314 2017-01-30 03:06:52
is to maybe have a function that accepts all stdin as [String]
jophish 2017-01-30 03:07:05
there are some neat and safe ways to do what you want, only reading a line when it's required (pipes, conduits etc...) however these libraries can be a little complicated to use sometimes and it might be best to start with something simpler
jophish 2017-01-30 03:07:27
grr12314: is your stdin finite?
grr12314 2017-01-30 03:08:20
yes, but assume i read the number of items or something so i know not to step over the limit
jophish 2017-01-30 03:08:21
because there does exist the function "getContents" which returns the whole of stdin as a string. Beware though, this function will not terminate if the input is unbounded.
grr12314 2017-01-30 03:08:27
like in programming puzzles
merijn 2017-01-30 03:08:56
grr12314: So, instead of actually reading something from stdin, why don't we define a notion of 'program fragment' or 'action' that *describes* a behaviour, without actually *performing* it. Which is roughly what IO is, 'getLine :: IO String' is the description of 'reading a line from stdin', and that description is always the same (thus pure), but executing such descriptions may end up yielding different
merijn 2017-01-30 03:09:02
results. But the actual execution is not observable *inside* haskell
jophish 2017-01-30 03:09:04
usually what I do for these things is define a data type for the pizzle input, and write a parser which goes from String to that type
jophish 2017-01-30 03:09:08
then use that with getContents
Ferdirand 2017-01-30 03:12:03
:t lines <$> getContents
lambdabot 2017-01-30 03:12:05
IO [String]
grr12314 2017-01-30 03:14:27
hm i guess im starting to see the light. or an incoming train, not sure
Ferdirand 2017-01-30 03:14:38
:t (\f -> interact (unlines . f . lines))
lambdabot 2017-01-30 03:14:39
([String] -> [String]) -> IO ()
grr12314 2017-01-30 03:15:03
i just realized that even if i had an infinite [String] and wanted to use it with functions that take some elements from it and process it
grr12314 2017-01-30 03:15:16
i'll still have to pass around "resto of list" between them
grr12314 2017-01-30 03:15:32
so its pretty much like passing around IO
Ferdirand 2017-01-30 03:15:47
congratulations, you just grokked (part of) monads
merijn 2017-01-30 03:16:28
This really has nothing to do with monads, tbh
piyush-kurur 2017-01-30 03:16:31
does anyone know how to put the contents of readme directly into the starting page of package
Ferdirand 2017-01-30 03:16:39
shhh, it's motivational
piyush-kurur 2017-01-30 03:16:56
I mean usually the staring page is generated from the .cabal file
Ferdirand 2017-01-30 03:17:39
but if you use getLine then do-notation is the sugar you need to have this IO passing behind the scenes, right ?
merijn 2017-01-30 03:18:14
You're not "passing" IO
merijn 2017-01-30 03:18:37
The point is, you can have IO in your language without monads and you could use monads in an impure language without IO
merijn 2017-01-30 03:19:39
It's just a happy coincidence that the interface for dealing with IO happens to nicely match the interface Monad provides.