Search Haskell Channel Logs

Saturday, January 28, 2017

#haskell channel featuring Dryvnt, boojinks, lambdabot, jre2, srhb, Axman6, and 5 others.

Jinxit 2017-01-27 23:46:05
ok so i've been away from haskell for too long
Jinxit 2017-01-27 23:46:25
what is it exactly that allows a monad to hide information when we don't have anything like "private" in haskell?
reactormonk 2017-01-27 23:46:29
So Text for textual data of any kind, and ByteString for binary data?
Dryvnt 2017-01-27 23:46:37
I have this app I've written in Rust. I used unstable libs, and they've since changed their syntax, so I have to basically rewrite the entire thing if I want to update the rust compiler on my server. Figured I might as well toy with a new language if I had to do a complete rewrite anyway. Remembered Haskell was pretty neat from my programming languages class like a year ago, so I'm here now. Woop woop
reactormonk 2017-01-27 23:46:41
Jinxit, why hide information?
Jinxit 2017-01-27 23:46:53
not intending to do it, just curious how it works
Axman6 2017-01-27 23:47:08
reactormonk: re Text vs ByteString, one represents text, the other represents strings of bytes. these are not the same thing (and shouldn't be confused). A ByteString can hold UTF-8 encoded text, but is not really appropriate for working with it as if it were text
boojinks 2017-01-27 23:47:18
Jinxit: it's not 'hiding' information
Axman6 2017-01-27 23:47:19
TExt is UTF-16 encoded text data
reactormonk 2017-01-27 23:47:31
Axman6, hmm. Is there something for UTF8?
systadmin 2017-01-27 23:47:43
hi
reactormonk 2017-01-27 23:47:47
o/
Axman6 2017-01-27 23:47:55
you convert Text into UTF-8 encoded ByteStrings
Axman6 2017-01-27 23:48:17
and can convert UTF-8 (or 16, or 32) encoded ByteStrings to Text
Jinxit 2017-01-27 23:48:21
boojinks: but i can't access the inner state of IO can i?
reactormonk 2017-01-27 23:48:47
Axman6, any way to tell the typesystem specifically it's a UTF-8 bytestring?
Axman6 2017-01-27 23:48:55
Jinxit: the "state" in IO is an implementation detail that doesn't really have anything to do with IO
Axman6 2017-01-27 23:49:10
reactormonk: ByteStrings are just a string of bytes, nothing more
systadmin 2017-01-27 23:49:32
I'm new to Haskell
reactormonk 2017-01-27 23:49:40
systadmin, everyone is at some point.
Axman6 2017-01-27 23:49:43
they're appropriate for writing and reading to/from files, sending over the network etc
systadmin 2017-01-27 23:49:55
I just have a quick question
reactormonk 2017-01-27 23:50:03
Axman6, not so much for JSON?
systadmin 2017-01-27 23:50:05
What are top level variables?
reactormonk 2017-01-27 23:50:14
systadmin, give it a good guess
Axman6 2017-01-27 23:50:16
reactormonk: can you send JSOK over the network?
Axman6 2017-01-27 23:50:21
JSON*
Jinxit 2017-01-27 23:50:27
Axman6: and my question is how that implementation detail is hidden
systadmin 2017-01-27 23:50:28
Um....
Axman6 2017-01-27 23:50:47
Jinxit: it's hidden in Haskell by not exporting the constructor for IO
Axman6 2017-01-27 23:50:54
systadmin: don't ask to ask, just ask ;)
systadmin 2017-01-27 23:51:07
Yeah, I'm confused with how TLV's work
reactormonk 2017-01-27 23:51:15
systadmin, example?
Axman6 2017-01-27 23:51:17
TLV's?
systadmin 2017-01-27 23:51:27
Axman6: top level variable
reactormonk 2017-01-27 23:51:29
Axman6, trying to make an case for switching https://github.com/freizl/hoauth2/blob/master/src/Network/OAuth/OAuth2/Internal.hs#L24 to Text
reactormonk 2017-01-27 23:51:41
systadmin, or aka, what's not clear?
systadmin 2017-01-27 23:52:16
Actually, I'll try looking around Stack Overflow first
Axman6 2017-01-27 23:52:54
reactormonk: I would guess those values make the most sense as ByteStrings, things like keys in crypto etc often are
Jinxit 2017-01-27 23:52:57
aha
Jinxit 2017-01-27 23:53:00
thanks
Axman6 2017-01-27 23:53:03
systadmin: what is your question
boojinks 2017-01-27 23:53:38
Jinxit: if you really want to see what's going on, then check out the source for IO
systadmin 2017-01-27 23:53:43
Nevermind, found the answer
boojinks 2017-01-27 23:53:45
not sure what you'd get out of it though :)
reactormonk 2017-01-27 23:53:47
Axman6, still encoded as utf8 if you skip down to the json instances.
Axman6 2017-01-27 23:53:50
ah, you asked in #haskell-beginners anyway
systadmin 2017-01-27 23:54:52
Yeah, I'm currently reading a Haskell book
Axman6 2017-01-27 23:55:15
reactormonk: if you believe it's textual data, then Text might be a better choice (but if you're just making it Text for the sake of it being Text, when it's always used as a ByteString you've not really won anything)
reactormonk 2017-01-27 23:55:56
"always used as a ByteString"?
Axman6 2017-01-27 23:56:08
what is the value used for?
reactormonk 2017-01-27 23:56:23
Packed back into JSON
reactormonk 2017-01-27 23:56:32
and/or Authorization HTTP headers
Axman6 2017-01-27 23:56:49
hmm, actually it'll be Text in the JSON Value already won't it... might as well make it Text =)
Axman6 2017-01-27 23:58:20
and any framework yo're doing HTTP with should be able to encode it as ByteStrings automatically for the headers
reactormonk 2017-01-27 23:59:35
Just sad Text is UTF-16, got more unicode planes to cover.
Axman6 2017-01-28 00:00:37
It's not a detailt you really ever have to worry about
Axman6 2017-01-28 00:00:44
detail*
Dryvnt 2017-01-28 00:02:39
I've made a project with stack. I want to use use a library, but I have to add the library's package as a dependency, which is fine. The problem is: how do I know what package each lib is in? In this case, I want to use Network.HTTP, but it seems that the 'http' package does not exist. Despite it being the package on hackage that has the Network.HTTP bits I want. Any help?
Axman6 2017-01-28 00:03:49
I believe the package is HTTP, it's case sensitive
Axman6 2017-01-28 00:03:58
@Hoogle Network.HTTP
lambdabot 2017-01-28 00:03:58
Maybe you meant: hoogle google
Axman6 2017-01-28 00:04:05
@hoogle Network.HTTP
lambdabot 2017-01-28 00:04:11
module Network.HTTP
lambdabot 2017-01-28 00:04:11
Network.URL HTTP :: Bool -> Protocol
lambdabot 2017-01-28 00:04:11
Network.Gravatar Http :: Scheme
Axman6 2017-01-28 00:04:20
hmm, shame that doesn't tell you
Dryvnt 2017-01-28 00:04:43
Seems HTTP is right.
systadmin 2017-01-28 00:04:56
I have another small question
Dryvnt 2017-01-28 00:04:57
Seems backwards to have things like this be case sensitive, but what can you do
Dryvnt 2017-01-28 00:04:59
Thanks.
systadmin 2017-01-28 00:05:12
What does `->` do?
systadmin 2017-01-28 00:05:26
Example: topLevenFunction :: Integer -> Integer
srhb 2017-01-28 00:06:04
systadmin: That symbol is a bit overloaded
Axman6 2017-01-28 00:06:04
it's the function arrow, thatv type says topLevenFunction is a function which when given an Integer, returns an Integer
boojinks 2017-01-28 00:06:10
systadmin: http://learnyouahaskell.com/types-and-typeclasses
srhb 2017-01-28 00:06:12
systadmin: In that example it's the function construction (type) operator
srhb 2017-01-28 00:06:24
systadmin: The left hand side is the argument (type) and the right hand side is the result (type)
systadmin 2017-01-28 00:06:59
So if I do "Integer -> String", it would return the output as a string?
systadmin 2017-01-28 00:07:16
From an integer to a string
srhb 2017-01-28 00:07:17
systadmin: That is the type of a function that takes an Integer as argument and gives you back a String, yes.
Axman6 2017-01-28 00:07:52
systadmin: no, a type is a promise of what it will do, changing it means the implementation must also change
systadmin 2017-01-28 00:08:06
I have no idea why would I want to do `Integer -> Integer` when I can make the type signature just plain Integer
boojinks 2017-01-28 00:08:32
systadmin: you're not defining any behaviour but simply a type.
srhb 2017-01-28 00:08:35
systadmin: (+2) is Integer -> Integer
Axman6 2017-01-28 00:08:37
systadmin: 1 is an integer, negate is a function which takes an Integer and returns an Integer
Axman6 2017-01-28 00:08:39
> 1 :: Integer
lambdabot 2017-01-28 00:08:42
1
Axman6 2017-01-28 00:08:48
:t negate :: Integer -> Integer
lambdabot 2017-01-28 00:08:50
Integer -> Integer
Axman6 2017-01-28 00:08:57
> negate (1 :: Integer)
lambdabot 2017-01-28 00:08:59
-1
systadmin 2017-01-28 00:09:22
Oh, so it returns a negative number?
boojinks 2017-01-28 00:09:34
systadmin: do you know any other programming languages?
Axman6 2017-01-28 00:09:39
in the case of negate, yes
systadmin 2017-01-28 00:09:50
boojinks: before Haskell, I've been doing some Python3
srhb 2017-01-28 00:09:52
systadmin: negate does. (Integer -> Integer) is the type of ALL functions that take an Integer as an argument and return a (possibly different) Integer as result.
boojinks 2017-01-28 00:10:50
ok well Python is dynamically typed so you won't be used to functions having 'types'. Which Haskell book are you reading?
vapid 2017-01-28 00:11:24
:t a
lambdabot 2017-01-28 00:11:26
Expr
systadmin 2017-01-28 00:12:56
Function Arrows is a bit hard to understand
systadmin 2017-01-28 00:13:14
boojinks: hold on, getting the link
srhb 2017-01-28 00:13:39
systadmin: They read as `Type of first argument -> Type of second argument -> Type of third argument -> Type of result`
srhb 2017-01-28 00:13:44
systadmin: Throw in as many arguments as you like.
srhb 2017-01-28 00:14:07
systadmin: They tell you nothing about the behaviour of the function aside from the type (which can be more than you initially imagine)
jre2 2017-01-28 00:14:18
can anyone suggest a decent library for haskell record<>json (de)serialization?
srhb 2017-01-28 00:14:30
jre2: Aside from aeson?
systadmin 2017-01-28 00:14:39
boojinks: http://haskellbook.com/
Axman6 2017-01-28 00:14:54
systadmin: have you ever written comments in Python code like "When given a String which has the server address in it, this method will return an Object representing the database connection"? in Haskell, you would write String -> DBConnection
implementation 2017-01-28 00:15:26
or even ServerAddr -> DBConnection
Axman6 2017-01-28 00:15:43
Python gives you no real way to talk about types, basically everything is some kind of Object
Axman6 2017-01-28 00:16:04
in Haskell we can describe these sorts of preconditions in a way the compiler can enforce
Axman6 2017-01-28 00:17:23
implementation: or ServerAddr -> IO DBConnection, or MonadIO => ServerAddr -> m DBConnection =)
boojinks 2017-01-28 00:17:24
systadmin: I have no experience with that book but I'd suggest you re-read the types section (or alternatively look at http://learnyouahaskell.com/types-and-typeclasses) - it can be difficult to get your head around especially if your only prior programming experience is with Python (which has a completely different take on types)
jre2 2017-01-28 00:18:06
srhb: is aeson the normally recommended option? I haven't kept up with haskell libraries that well the last few years
Axman6 2017-01-28 00:18:38
jre2: at the moment yes, it's the most widely used anyway
reactormonk 2017-01-28 00:18:41
jre2, also kinda new here, still looks good
reactormonk 2017-01-28 00:18:58
Why not use String btw? Because UTF-32?
Axman6 2017-01-28 00:19:50
String is bad for many reasons, except if you need to accurately work with all unicode text. it's extremely space inefficient
systadmin 2017-01-28 00:20:31
I gotta get some Haskell related plugins for my .vimrc
reactormonk 2017-01-28 00:20:45
Sounds like UTF-32
Axman6 2017-01-28 00:22:07
String is a linked list of Chars (which represent all unicode values), so there's an overhead of something like 2 words (32 or 64 bit) per character
Axman6 2017-01-28 00:22:26
it's not a packed representation like Text is
reactormonk 2017-01-28 00:24:48
So basically UTF-32
reactormonk 2017-01-28 00:25:07
And Text is UTF-16 from what I understand. And use ByteString if you want UTF-8
Axman6 2017-01-28 00:26:48
well, ByteString is capable of holding UTF-8 encoded data, as well as UTC-16 or 32, ascii, or anything else
boojinks 2017-01-28 00:27:54
reactormonk: the important difference is that String is a linked list and ByteString and Text are packed
reactormonk 2017-01-28 00:28:01
ohh
reactormonk 2017-01-28 00:28:33
Is there a data type for UTF-8 specifically?
Axman6 2017-01-28 00:28:40
no
reactormonk 2017-01-28 00:28:51
How come?
Axman6 2017-01-28 00:29:08
do you know you need it though? I feel you don't understand what the difference between these different things is and what that difference means
reactormonk 2017-01-28 00:30:46
Usually no, UTF-16 covers a large part of unicode. But from what I understand, you can run into trouble if someone tosses you a character that's not in the first code page.
Axman6 2017-01-28 00:31:30
have you read the Text docs? it specifically mentions that occurance in right at the top of the page
Axman6 2017-01-28 00:31:50
https://hackage.haskell.org/package/text-1.2.2.1/docs/Data-Text.html
Axman6 2017-01-28 00:32:48
see also https://hackage.haskell.org/package/text-1.2.2.1/docs/Data-Text-Encoding.html
reactormonk 2017-01-28 00:33:02
https://hackage.haskell.org/package/text-1.2.2.1/docs/Data-Text.html#g:2 this part?
Axman6 2017-01-28 00:33:11
but since you're work with Aeson Values, you have no choice but to use Text to begin with
Axman6 2017-01-28 00:33:16
yes
reactormonk 2017-01-28 00:33:49
Yeah, let's stop bikeshedding and get back to coding and hope to not hit that case.
systadmin 2017-01-28 00:38:17
So in function arrows
systadmin 2017-01-28 00:39:01
It sort of like, enforces what kind of output it should print?
systadmin 2017-01-28 00:39:45
Like if the parameter after -> is Integer
systadmin 2017-01-28 00:39:46
The output should be an integer?
boojinks 2017-01-28 00:40:25
Well, it won't 'print' anything, but yes, you're telling the compiler that the result of the function HAS to be an Integer.
systadmin 2017-01-28 00:41:32
Oh okay, I understand now
boojinks 2017-01-28 00:41:35
if you then actually wrote the function to return a String, the compiler would tell you that you've messed up.
systadmin 2017-01-28 00:44:33
But what if I have several ->'s for one function?
systadmin 2017-01-28 00:44:52
Like: something :: Int -> Int -> Int