Search Haskell Channel Logs

Sunday, January 29, 2017

#haskell channel featuring Theophane, Tuplanolla, roxxik, lambdabot, excelsiora, kirillow,

excelsiora 2017-01-29 03:45:48
got it
excelsiora 2017-01-29 03:46:44
ok, now I need to learn string formatting. printf the way to do it?
epta 2017-01-29 03:46:51
are there any resharper analogues for haskell besides stylish-haskell?
Theophane 2017-01-29 03:47:22
epta: I use stylish-haskell, but perhaps you could try hlint
epta 2017-01-29 03:47:49
Theophane: anything else?
Theophane 2017-01-29 03:48:15
epta: idk \o/
excelsiora 2017-01-29 03:50:11
Theophane: thanks again, by the way
Theophane 2017-01-29 03:50:21
you're welcome :)
excelsiora 2017-01-29 03:59:32
so... printf?
ertes 2017-01-29 04:00:52
excelsiora: it's certainly the most accessible in terms of availability (it's in base)
ertes 2017-01-29 04:01:31
excelsiora: but i think it's safe to say that it's also the least favourite solution simply because haskell doesn't have the type system to support it properly
ertes 2017-01-29 04:01:56
excelsiora: printf "%s" (0 :: Integer) -- not a type error… will throw a run-time exception instead
ertes 2017-01-29 04:02:40
(at least it won't be a memory violation the way it would be in C)
ertes 2017-01-29 04:03:36
for number formatting see the Numeric module, which is also in base
ertes 2017-01-29 04:04:31
for general formatting you can very often use ShowS, but not a lot is predefined
ertes 2017-01-29 04:05:06
> (showString "A number: " . showHex 254 . showChar '!') ""
lambdabot 2017-01-29 04:05:09
"A number: fe!"
ertes 2017-01-29 04:05:29
the functions from Numeric are all compatible with ShowS
ertes 2017-01-29 04:07:29
it doesn't quite replace printf, because stuff like padding is missing
Tuplanolla 2017-01-29 04:20:10
Is there a way to generalize or express this better? I have `view _1 xs /= view _2 xs` in a guard.
kirillow 2017-01-29 04:21:02
I want to load the contents of a file as a ByteString before compilation. How do I do that?
Tuplanolla 2017-01-29 04:21:15
I feel like there ought to be some way to say `equal xs`.
excelsiora 2017-01-29 04:27:50
why are there so few examples in the haskell documentation?
excelsiora 2017-01-29 04:30:36
this entire page - not a single example: http://hackage.haskell.org/package/base-4.9.1.0/docs/Text-Printf.html
excelsiora 2017-01-29 04:31:04
What's the thought process on that?
kirillow 2017-01-29 04:31:45
nvm
excelsiora 2017-01-29 04:31:52
"If we make examples, we'll attract programmers that learn by example instead of by reading the specifications, and that would be bad."
ertes 2017-01-29 04:32:10
excelsiora: probably: "i don't like to come up with examples right now", thought by every documentation writer so far… care to become the first exception? =)
kirillow 2017-01-29 04:32:52
b-but there's an example on that page
excelsiora 2017-01-29 04:33:09
show me!
kirillow 2017-01-29 04:33:17
it's introduced with the words "for example:"
ertes 2017-01-29 04:33:33
hehe
ertes 2017-01-29 04:33:57
i don't know… as haskell programmers we're often comfortable just looking at types
excelsiora 2017-01-29 04:34:30
> printf "%d\n" (23::Int)
lambdabot 2017-01-29 04:34:33
error:
lambdabot 2017-01-29 04:34:33
• Ambiguous type variable 'a0' arising from a use of 'show_M561607525422...
lambdabot 2017-01-29 04:34:33
prevents the constraint '(Show a0)' from being solved.
ertes 2017-01-29 04:34:48
> printf "%d\n" (23::Int) :: String
lambdabot 2017-01-29 04:34:50
"23\n"
excelsiora 2017-01-29 04:35:27
I found actual examples in a collapsed text box.
excelsiora 2017-01-29 04:36:04
halfway through the doc page. Where it saves 6 lines. Not sure how users benefit from that.
excelsiora 2017-01-29 04:37:15
And as I just demonstrated, there's apparently an issue with the examples...
excelsiora 2017-01-29 04:38:13
> printf "%s %s\n" "Hello" "World"
lambdabot 2017-01-29 04:38:15
error:
lambdabot 2017-01-29 04:38:16
• Ambiguous type variable 'a0' arising from a use of 'show_M572878973673...
lambdabot 2017-01-29 04:38:16
prevents the constraint '(Show a0)' from being solved.
excelsiora 2017-01-29 04:38:24
> printf "%s %s\n" "Hello" "World" :: String
lambdabot 2017-01-29 04:38:27
"Hello World\n"
Tuplanolla 2017-01-29 04:38:30
It's waiting for more arguments, excelsiora.
ertes 2017-01-29 04:38:50
the issue is: you must understand the basics of haskell's type system
Tuplanolla 2017-01-29 04:39:00
The type checker doesn't know what's inside the string.
ertes 2017-01-29 04:39:19
it's more like: the type checker doesn't know whether you want a String or an IO () in the end
excelsiora 2017-01-29 04:39:29
printf "%.2f\n" pi :: String
Tuplanolla 2017-01-29 04:39:54
:t printf "%s %s\n" "Hello" "World" :: String -> String
lambdabot 2017-01-29 04:39:56
String -> String
excelsiora 2017-01-29 04:40:02
Tuplanolla: these are examples directly from the documentation
ertes 2017-01-29 04:40:11
(printf "%d\n" 23) -- this can be one of three things
excelsiora 2017-01-29 04:40:33
afk
ertes 2017-01-29 04:40:39
1. a function that takes another argument to format (haskell's type system is not powerful enough to figure out that the format string does not specify any more)
ertes 2017-01-29 04:40:44
2. a String
ertes 2017-01-29 04:40:46
3. an IO ()
roxxik 2017-01-29 04:41:05
this is where looking at types stops being useful
roxxik 2017-01-29 04:41:13
so examples are needed
ertes 2017-01-29 04:44:48
there are more constructive ways to complain, especially in a community driven mostly by volunteers