Search Haskell Channel Logs

Tuesday, February 7, 2017

#haskell channel featuring dramforever, Denommus, dfeuer, opqdonut, __monty__, noan, and 17 others.

merijn 2017-02-07 02:45:26
systadmin: I've always liked the "IO as program fragments" explanations. Values with an IO type can be thought of as 'fragments' of a program that describe some behaviour. For example, 'getLine :: IO String' is the description of how to read a line from stdin. These fragments can be composed into bigger components
Denommus 2017-02-07 02:45:30
systadmin: you use the IO type in general to perform side effects (such as operating with files). IO () specifically is the type of a function that might perform some side effect but doesn't evaluate to a value
merijn 2017-02-07 02:45:42
Denommus: Haskell doesn't have side effects
merijn 2017-02-07 02:45:49
That's the entire point
systadmin 2017-02-07 02:46:13
So IO doesn't really give me an output?
merijn 2017-02-07 02:46:33
They're called *side* effects because they're invisible in the type of a function. In haskell they *are* visible, so they're not *side* effects, they're just *effects*
merijn 2017-02-07 02:46:47
(they happen "on the side" of the function's execution)
merijn 2017-02-07 02:47:00
systadmin: Let's take a step back
merijn 2017-02-07 02:47:16
systadmin: You've probably heard 'Haskell is pure', yes?
systadmin 2017-02-07 02:47:31
I guess so
Denommus 2017-02-07 02:47:38
merijn: meh. I believe that's just a confusing statement that helps nobody. "Haskell doesn't perform side-effects, instead it generates instructions that actually perform side-effects". Ok, you can say the same thing about C. You actually program with the pure macro language, that generates actual expressions that perform side-effects. Big deal
merijn 2017-02-07 02:48:25
systadmin: So, what does this mean? It means that "a function, when given the same input, will always give the same output" and also that you whether a function is evaluated zero, once, or twice, doesn't impact the rest of your program
lpaste_ 2017-02-07 02:48:33
KyleFang pasted "How to instance Monad?" at http://lpaste.net/352172
merijn 2017-02-07 02:49:05
systadmin: So, let's think about a non-existent 'putStrLn :: String -> IO ()', well if that immediately printed something to stdout, we'd pretty obviously lose purity
Denommus 2017-02-07 02:49:20
http://conal.net/blog/posts/the-c-language-is-purely-functional
merijn 2017-02-07 02:49:43
Denommus: My stance is that pedantic correctness is important when teaching beginners to avoid letting subtle confusions slip in and propagate
kylefang 2017-02-07 02:50:28
hey guys, really new to haskell, trying to write a Maybe look alike... having trouble finding the example source to follow. this is what I've current at http://lpaste.net/352172 . Can you point me at some syntax guide or example code maybe?
merijn 2017-02-07 02:50:46
systadmin: Well, if we take the IO as program fragments interpretation 'putStrLn :: String -> IO ()' is fine. If we call it with the same input (string) we always get the same result a "description of how to print that string" and it's perfectly pure. Whether we do it zero, once, or more is irrelevant
merijn 2017-02-07 02:51:44
systadmin: So what you end up with is a pure programming language that lets you construct programs by combining these sorts of descriptions. The crucial thing is that the *execution* of these fragments can never be observed (or impact) by the pure code
merijn 2017-02-07 02:52:24
systadmin: Look at 'main :: IO ()', it's basically saying that main is a single program (fragment) which, when executed, may do all sorts of things, like print to stdout, read from stdin, etc.
merijn 2017-02-07 02:53:01
systadmin: How does that get run? Well, the runtime system has machinery to actually execute these IO programs. But this execution can't impact the way pure code evaluates
dfeuer 2017-02-07 02:53:26
merijn: I do work on containers, although I have a bit less time for it now.
merijn 2017-02-07 02:53:52
dfeuer: So, I have some function I need/want, but I'm not sure if the machinery is in there and if not if there's support to add
systadmin 2017-02-07 02:53:57
So it can't alter/mess with/etc the evaluation?
merijn 2017-02-07 02:54:03
systadmin: Right
dfeuer 2017-02-07 02:54:10
merijn: whaddya want?
kylefang 2017-02-07 02:54:11
Found it... thx https://hackage.haskell.org/package/base-4.9.1.0/docs/src/GHC.Base.html#line-665 Dash was having trouble jumping to correct line. :)
merijn 2017-02-07 02:55:06
dfeuer: I have two sets A and B which potentially intersect and I want to both insert missing elements from B into A and find out which elements were inserted
dfeuer 2017-02-07 02:56:00
merijn: I think that'll fall out of adding an alterF analogue for Set, which I was already hoping to do.
merijn 2017-02-07 02:56:09
I can do difference first and then union, but I feel like that'd be much nicer/faster to do at once
dfeuer 2017-02-07 02:56:12
But I could be wrong.
dfeuer 2017-02-07 02:56:17
Oh, you want *that*.
dfeuer 2017-02-07 02:56:25
difference and union too.
dfeuer 2017-02-07 02:56:42
Hmmm....
systadmin 2017-02-07 02:57:35
I'm just working on a little project btw :)
dfeuer 2017-02-07 02:59:14
merijn: we don't have any other such combos, because it's a bit hard to know where to stop. Can you try implementing it by importing Data.Set.Internal? What gains do you see?
merijn 2017-02-07 02:59:23
Unlike Map there's no operation that allows you to both "set" *and* check if it was already in there, so you can simply reformulate this as "foldr insert setA setB" either
dfeuer 2017-02-07 02:59:47
merijn: well, *that* functionality is probably coming.
Profpatsch 2017-02-07 03:00:03
noan: Nobody answered your question; if App (Key User) is a type of kind *, then App is a type constructor of kind * -> * with one argument, (Key User).
dfeuer 2017-02-07 03:00:14
(alterF, specifically)
merijn 2017-02-07 03:00:21
ok, that's good :)
Profpatsch 2017-02-07 03:00:37
noan: (Key User) is of kind *, Key of kind * -> * and User of kind *
Profpatsch 2017-02-07 03:00:50
It's like function application really.
merijn 2017-02-07 03:01:25
dfeuer: heh, what timezone are you in?
Profpatsch 2017-02-07 03:01:58
merijn: Since it's 15:00 here in Germany, probably LA time?
Profpatsch 2017-02-07 03:02:20
Or UK and he went to bed at 6am :)
opqdonut 2017-02-07 03:02:26
merijn: how about using Data.Map.mergeWithKey?
merijn 2017-02-07 03:02:48
opqdonut: I'm using IntSet, I was just observing the absence of that functionality for Sets
opqdonut 2017-02-07 03:02:58
mmh
merijn 2017-02-07 03:03:00
Profpatsch: I was under the impression he was closer to my timezone :)
Profpatsch 2017-02-07 03:04:23
merijn: which is? :)
taktoa 2017-02-07 03:04:30
seems like maryland: http://math.stackexchange.com/users/17596/dfeuer
merijn 2017-02-07 03:04:44
Profpatsch: CET
merijn 2017-02-07 03:04:58
Or he just has an unhealthy sleep pattern if he's in maryland :p
Profpatsch 2017-02-07 03:05:23
merijn: Hm, but CET is 15:00 right now, right?
Profpatsch 2017-02-07 03:05:41
If it's Central European Time.
merijn 2017-02-07 03:05:49
Yes
jchia_ 2017-02-07 03:06:28
How do I get the length of a sized vector (Data.Vector.Sized) without using undefined? I.e. given the type of the sized vector, I want to get the length. I know how to get the size using undefined: Data.Vector.Sized.length (undefined :: Data.Vector.Sized.Vector 123 Char)
systadmin 2017-02-07 03:06:47
What should I use to define a factorial function?
dramforever 2017-02-07 03:07:22
systadmin: Try to say in English first
dramforever 2017-02-07 03:07:30
What's the factorial of n?
taktoa 2017-02-07 03:07:37
systadmin: https://www.willamette.edu/~fruehr/haskell/evolution.html
dramforever 2017-02-07 03:07:53
Okay, this has got a little bit out of hand
jophish 2017-02-07 03:08:45
jchia_: hi, this is the vector-sized package, right?
jchia_ 2017-02-07 03:08:52
jophish: yes
jophish 2017-02-07 03:09:33
undefined will work there, but I'm surprised I didn't add a version taking a Proxy :)
jophish 2017-02-07 03:09:45
you could also just use the nat from the type
jophish 2017-02-07 03:10:20
ah, there is a version which returns a proxy, not quite what you want
jophish 2017-02-07 03:11:17
jchia_: You might just want to use https://hackage.haskell.org/package/base-4.9.1.0/docs/GHC-TypeLits.html#v:natVal
jophish 2017-02-07 03:12:13
so you have something like: length'' :: forall n a. Vector n a -> Natural; length'' = fromInteger (natVal (Proxy @n))
jophish 2017-02-07 03:12:26
sorry that should have been: length'' _ = ...
jophish 2017-02-07 03:13:20
That's using scoped type variables to get the length type variable in scope in the expression, so it can be used to type the 'Proxy' value being given to 'natVal'
Profpatsch 2017-02-07 03:13:23
defEndpoint :: forall p i o m ctx. (MonadIO m, HasRep p) => Endpoint p i o -> HVectElim p (HVectElim (MaybeToList i) (ActionCtxT ctx m o)) -> SpockCtxT ctx m ()
jchia_ 2017-02-07 03:13:24
jophish: Thanks. This is using OverloadedLabels, right?
Profpatsch 2017-02-07 03:13:30
Yay Haskell webframeworks
jophish 2017-02-07 03:13:32
It's using TypeApplication
jophish 2017-02-07 03:13:41
s
jophish 2017-02-07 03:13:52
you'll also need a KnownNat constraint in there
jophish 2017-02-07 03:14:33
jchia_: please let me know if there's anything I can help you with with vector-sized
jophish 2017-02-07 03:15:28
anything else*
jchia_ 2017-02-07 03:15:38
jophish: I think I understand length''. Why do we want to return Natural instead of Integer?
merijn 2017-02-07 03:15:51
jchia_: Because negative lengths are impossible
jophish 2017-02-07 03:16:17
sadly, natVal was introduced before Natural
jophish 2017-02-07 03:16:26
I believe this is being corrected in 8.2 though
jophish 2017-02-07 03:16:30
or a new module introduced
jchia_ 2017-02-07 03:19:33
jophish: I see. Thanks.
jophish 2017-02-07 03:20:14
If you don't need to guarantee that the result is non-negative then you could return Integer and remove the fromInteger
jchia_ 2017-02-07 03:20:38
merijn: Thanks
dramforever 2017-02-07 03:21:17
I feel Natural is, it's not that useful because it doesn't let you have negative intermediate results
phadej 2017-02-07 03:22:01
FWIW, natVal in GHC8.2 will return Natural
dramforever 2017-02-07 03:22:12
which is, actually more natural (no pun intended)
phadej 2017-02-07 03:22:47
ah, someone already mentioned that
jophish 2017-02-07 03:23:16
dramforever: Is that like saying Float isn't that useful because it doesn't let you have complex intermediate results?
jophish 2017-02-07 03:23:22
:P
dramforever 2017-02-07 03:24:54
complex isn't that natural
dramforever 2017-02-07 03:25:06
real is enough closed on most operations
dramforever 2017-02-07 03:26:04
like I don't really want to restrict myself to a + b - c not a - c + b because the latter may underflow or something
phadej 2017-02-07 03:26:29
dramforever: in practice you rarely substract naturals
jophish 2017-02-07 03:26:46
recently we've been using quite a lot of constraints, making sure that naturals are above a certain value
dramforever 2017-02-07 03:26:52
rarely?
dramforever 2017-02-07 03:27:23
I guess I need more inherently non-negative things to use Natural...
merijn 2017-02-07 03:27:32
Any guesstimate for reasonable "max URL length" for querying servers? Or should I just binary search to figure out the limit for a specific server and then use that
phadej 2017-02-07 03:27:36
fwiw, I probably never needed to substract two lengths of vectors for example
Logio 2017-02-07 03:28:55
if you are substracting them, they aren't really naturals, are they?
dramforever 2017-02-07 03:29:08
Logio: maybe
phadej 2017-02-07 03:29:18
well, I can imagine situation where you pad the shorter one so they are of equal length
dramforever 2017-02-07 03:29:49
Yeah, when you subtract the smaller amount from the larger amount
phadej 2017-02-07 03:30:05
but then I'd use `Natural -> Natural -> Integer` function
phadej 2017-02-07 03:30:16
or `Natural -> Natural -> (Bool, Natural)`
dramforever 2017-02-07 03:30:22
:(
phadej 2017-02-07 03:30:43
yeah, that's the reason people had `null` in Java ;)
phadej 2017-02-07 03:30:52
(sorry, for overshooting)
dramforever 2017-02-07 03:30:54
numbers are hard
Logio 2017-02-07 03:30:55
what about (-) :: Natural -> Natural -> Maybe (Natural)?
dramforever 2017-02-07 03:30:59
ADTs are better
phadej 2017-02-07 03:31:07
Logio: there is minusNaturalMaybe
dramforever 2017-02-07 03:31:11
Logio: now arithmetic got way harder
phadej 2017-02-07 03:31:19
but you cannot have (-) with that type
Logio 2017-02-07 03:31:38
yeah
exio4 2017-02-07 03:31:39
dramforever: you have to use combinators then
dramforever 2017-02-07 03:31:51
arithmetic got way harder
Logio 2017-02-07 03:32:01
I actually sinned recently and implemented a Num instance for clifford algebras
Logio 2017-02-07 03:32:20
now there's arithmetic gone hard
dramforever 2017-02-07 03:32:26
It's remarkable how dealing with immutable abstract things and ADTs are much easier...
exio4 2017-02-07 03:32:27
(`minus` (plus 5 7)) <$> (minus 4 3) == (4 - 3) - (5 + 7)
phadej 2017-02-07 03:32:34
dramforever: well, I think that we should use compiler to catch bugs, and not add 'if x < 0 ...' checks
merijn 2017-02-07 03:33:27
phadej: So...LiquidHaskell? :)
dramforever 2017-02-07 03:33:36
Well, aren't 'Natural's 'if x < 0'?
dramforever 2017-02-07 03:34:36
Just the 'if x < 0' get everywhere and go out of hand and get annoying and whatever...
phadej 2017-02-07 03:34:36
merijn: In some cases yeah, but I still think you can get quite far with just NonEmpty, then with { [x] | len x > 0 }
Logio 2017-02-07 03:35:01
on that note, does anyone know if base expects (*) to possibly be non-commutative?
phadej 2017-02-07 03:35:15
Logio: base doesn't expect it to be anything
quchen 2017-02-07 03:35:16
(*) has no laws.
phadej 2017-02-07 03:35:19
^
__monty__ 2017-02-07 03:36:02
I'm looking for a library that provides functionality to search a sorted file for line prefix. Do I really have to implement binary search for this myself?
dramforever 2017-02-07 03:36:31
phadej: but then stuffs like (^) uses (*) and they sure have assumptions
phadej 2017-02-07 03:36:46
merijn: but I have no opinion whether I prefer external (refinement types) or internal (gadts to the next level) "more precise types"
dramforever 2017-02-07 03:36:56
> x ^ 0x5a -- Perhaps we can see?
lambdabot 2017-02-07 03:36:58
x * x * (x * x) * (x * x * (x * x)) * (x * x * (x * x) * (x * x * (x * x))) ...
dramforever 2017-02-07 03:37:21
stupid idea, that doesn't really show anything...
systadmin 2017-02-07 03:37:32
Is there a way to remove the first letter in a word?
Logio 2017-02-07 03:37:32
Anything that uses (*) through Product should be fine due to Monoid laws, I guess
__monty__ 2017-02-07 03:38:24
systadmin: If the word is a String, simply use "tail"
systadmin 2017-02-07 03:38:53
oh...
noan 2017-02-07 03:38:58
Profpatsch, http://www.reactiongifs.com/r/eli5.gif I think I need to go read LYAHFGG from the beginning...
systadmin 2017-02-07 03:39:00
Okay, thanks
dramforever 2017-02-07 03:39:01
I would hesitate to use a Num instance that math doesn't really agree or something
noan 2017-02-07 03:39:04
but thanks
dramforever 2017-02-07 03:39:17
sorry ignore me
Profpatsch 2017-02-07 03:39:53
noan: Some people don't like LYAH, it very much helped me in the first stages.
Profpatsch 2017-02-07 03:40:25
You can also buy the http://haskellbook.com/, which is praised by many (no experience here)
noan 2017-02-07 03:40:37
Profpatsch, Do you know any decent books that would be approachable for someone new to FP but not OOP etc?
merijn 2017-02-07 03:40:38
Profpatsch: I think the issue is that LYAH was better than everything before it and came out during a rather quick growth of Haskell. But it's not very didactically sound and newer things tend to be better
quchen 2017-02-07 03:40:57
LYAH is very shallow, but it got me interested in Haskell. :-)
dramforever 2017-02-07 03:41:04
systadmin: uh, are you learning Haskell *by* writing small utility programs?
Profpatsch 2017-02-07 03:41:10
Aaaand, it's the LYAH discussion again. :P
merijn 2017-02-07 03:41:36
quchen: Sure, same here
noan 2017-02-07 03:41:38
I would but I don't really have expendable income, and I don't wanna pirate Chris and Julie's book. They worked damn hard at it and Chris is super nice.
systadmin 2017-02-07 03:41:39
I mainly read Haskell Book, but I g to LYAH for reference
noan 2017-02-07 03:41:46
(I've not spoken to Julie)
merijn 2017-02-07 03:41:48
quchen: But rereading it it's...rather unsound :)
dramforever 2017-02-07 03:41:50
oh good
thatguy 2017-02-07 03:41:51
Is there something similar to foldr but instead of going through a finite list I can pass it something like "repeat a" and a termination conidition?
Profpatsch 2017-02-07 03:41:54
noan: If you know JS "Purescript by Example" is your book.
systadmin 2017-02-07 03:41:58
dramforever: no, I'm reading a book. But I'm making a small utility program just for fun
dramforever 2017-02-07 03:42:03
good
merijn 2017-02-07 03:42:16
noan: If you ask Chris he'll gladly give you a discounted (or maybe free?) version if you don't have money
dramforever 2017-02-07 03:42:16
thatguy: foldr can do that
kadoban 2017-02-07 03:42:17
thatguy: Sounds kind of like unfoldr to me? But that's just a guess.
dramforever 2017-02-07 03:42:19
:t foldr
lambdabot 2017-02-07 03:42:21
Foldable t => (a -> b -> b) -> b -> t a -> b
dramforever 2017-02-07 03:42:37
see the second argument in (a -> b -> b), the b?
Profpatsch 2017-02-07 03:42:39
Actually, it might be easier learning Purescript first, since it has less historical baggage and no laziness.
quchen 2017-02-07 03:42:40
> foldr const 0 [1..]
lambdabot 2017-02-07 03:42:44
1
dramforever 2017-02-07 03:42:53
If the condition is reached just ignore the b
dramforever 2017-02-07 03:43:11
const is a good b-ignoring function obviously
noan 2017-02-07 03:43:20
Profpatsch, I'm already working on a project in haskell. I wanna learn the necessary components to get some stuff working and understand it at present. a detour of that size is maybe a bit much
Profpatsch 2017-02-07 03:43:40
I still don't know what a HeytingAlgebra is. :(
c_wraith 2017-02-07 03:43:45
Profpatsch: Why would you not want laziness? It's what makes basic combinators work.
noan 2017-02-07 03:43:46
I think I need mainly a) a syntax review and b) a better understanding of how converting between types works in haskell
dramforever 2017-02-07 03:43:50
noan: What are your previous experiences?
Profpatsch 2017-02-07 03:44:08
noan: That's nice, so definitely stick with one of the Haskell books.
Profpatsch 2017-02-07 03:44:23
It should be fairly quick to learn the other once you master one.
noan 2017-02-07 03:44:27
dramforever, C#, Ruby, Javascript + underscore, a bit of scala.
merijn 2017-02-07 03:44:28
noan: tbh, depending on your background you might consider just reading the spec
quchen 2017-02-07 03:44:28
No laziness *is* historical baggage :-C
sm 2017-02-07 03:44:29
noan: how about Haskell Tutorial And Cookbook
merijn 2017-02-07 03:44:52
noan: The Haskell Report is pretty readable, especially compared to monstrosities like C
merijn 2017-02-07 03:44:55
quchen: Boo you!
merijn 2017-02-07 03:45:03
quchen: Laziness is the only sane default!