surelyourejoking 2017-03-08 00:56:25
I'm doing the Learn You a Haskell tutorials, and I don't understand the syntax for `groupBy`
surelyourejoking 2017-03-08 00:56:41
e.g groupBy (\x y -> (x > 0) == (y > 0)) values
surelyourejoking 2017-03-08 00:57:28
where values is a list of some positive and negative floats
Axman6 2017-03-08 00:58:20
which part do you not understand?
surelyourejoking 2017-03-08 00:58:28
I suppose the lambda
surelyourejoking 2017-03-08 00:58:54
(\x y -> (x>0) == (y>0))
Axman6 2017-03-08 00:58:55
(\x y -> (x > 0) == (y > 0)) is a lambda function which takes two argument named x and y and returns the expression (x > 0) == (y > 0)
surelyourejoking 2017-03-08 00:59:11
what does the right hand side evaluate to
Axman6 2017-03-08 00:59:18
> (\x y -> (x > 0) == (y > 0)) 1 1
lambdabot 2017-03-08 00:59:24
mueval-core: Time limit exceeded
int-e 2017-03-08 00:59:27
> let x = 1; y = -1 in ((x > 0), (y > 0), (x > 0) == (y > 0))
lambdabot 2017-03-08 00:59:32
(True,False,False)
Axman6 2017-03-08 00:59:34
uh, come on lambdabot
surelyourejoking 2017-03-08 00:59:35
so it's true if x and y are positive
Ferdirand 2017-03-08 00:59:56
or if x and y are not positive
Axman6 2017-03-08 01:00:24
(assuming 0 is negative =) )
surelyourejoking 2017-03-08 01:01:10
ok it's an XNOR logic gate then.
surelyourejoking 2017-03-08 01:01:15
right I understand the lambda function then
Axman6 2017-03-08 01:01:27
looks like a nice way to find groups of increasing or decreasing runs... but that's not actually what it'll do sadly, because groupBy's behaviour is a surprising
Axman6 2017-03-08 01:02:01
> groupBy (\x y -> (x > 0) == (y > 0)) [1,2,3,2,1,0,-1,-2,-3,-2,-1]
lambdabot 2017-03-08 01:02:08
mueval-core: Time limit exceeded
Axman6 2017-03-08 01:02:16
what are you doing lambdabot!
int-e 2017-03-08 01:02:16
Axman6: the given relation is symmetric, so groupBy should not produce any surprises.
int-e 2017-03-08 01:02:28
@undef
lambdabot 2017-03-08 01:02:29
Undefined.
int-e 2017-03-08 01:02:36
> groupBy (\x y -> (x > 0) == (y > 0)) [1,2,3,2,1,0,-1,-2,-3,-2,-1]
Axman6 2017-03-08 01:02:36
> groupBy (\x y -> (x > 0) == (y > 0)) [1,2,3,2,1,0,-1,-2,-3,-2,-1]
lambdabot 2017-03-08 01:02:40
[[1,2,3,2,1],[0,-1,-2,-3,-2,-1]]
lambdabot 2017-03-08 01:02:41
[[1,2,3,2,1],[0,-1,-2,-3,-2,-1]]
surelyourejoking 2017-03-08 01:02:56
so let me clarify, whenever the equality condition is met, groupBy causes a split in the list?
int-e 2017-03-08 01:18:16
surelyourejoking: No, it always compares the next element to the first element of the current group. But if the relation is an equivalence relation then your model produces the same results.
surelyourejoking 2017-03-08 01:21:31
and as you've said, I should stick to equivalence relations.Thank you for the help!
cocreature 2017-03-08 02:09:19
*called
kuribas 2017-03-08 02:10:00
or id?
kuribas 2017-03-08 02:10:18
:t id putStrLn
lambdabot 2017-03-08 02:10:22
String -> IO ()
kuribas 2017-03-08 02:10:45
magthe: try #haskell-emacs
Hafydd 2017-03-08 02:11:55
But it doesn't have the property that safePerformIO . unSafePerformIO = id. It can't recover the nondeterminism from the result of unSafePerformIO.
kuribas 2017-03-08 02:26:08
There should be a way to delete a range from a Map in O(log n).
merijn 2017-03-08 02:26:57
kuribas: Isn't dfeuer working on that kinda thing?
kuribas 2017-03-08 02:27:15
merijn: that would be great.
Ferdirand 2017-03-08 02:28:28
assuming the number of elements covered by the range is << n ?
maerwald 2017-03-08 02:28:47
any useful xml package with xpath support?`the 'xml' package doesn't seem to have it and hxt is just useless complexity
Ferdirand 2017-03-08 02:28:49
or do you ignore the average gc cost ?
kuribas 2017-03-08 02:29:41
Ferdirand: I don't think GC is linear in garbage collected.
kuribas 2017-03-08 02:29:50
ghc likes garbage.
quchen_ 2017-03-08 02:31:49
It's copying, so shouldn't it be linear in the garbage *not* collected?
spatial 2017-03-08 02:32:32
http://pastebin.com/C3Fp7MAx This has the indentation problem.
quchen_ 2017-03-08 02:34:08
… up to linear factors ;-)
kuribas 2017-03-08 02:34:08
quchen_: it doesn't copy the hole heap, does it?
quchen_ 2017-03-08 02:34:08
kuribas: Nope, it's generational
quchen_ 2017-03-08 02:34:08
spatial: There is no »else«
spatial 2017-03-08 02:34:08
I thought that is acceptable
kuribas 2017-03-08 02:36:29
:t when
lambdabot 2017-03-08 02:36:31
Applicative f => Bool -> f () -> f ()
kuribas 2017-03-08 02:36:48
spatial: perhaps you want "when"
merijn 2017-03-08 02:36:58
Basically, GHC's GC is optimised for high-throughput workloads with a, preferably, not too excessive resident set
spatial 2017-03-08 02:37:35
kuribas: haven't seen when
quchen_ 2017-03-08 02:37:51
?src when
lambdabot 2017-03-08 02:37:51
when p s = if p then s else return ()
maerwald 2017-03-08 02:38:01
merijn: where does it have xpath support?
merijn 2017-03-08 02:38:18
maerwald: Not direct xpath support, but the combinators are modelled after xpath
kuribas 2017-03-08 02:38:44
spatial: look at lambdabots output
maerwald 2017-03-08 02:38:56
merijn: that's pretty limited, xpath is a language
merijn 2017-03-08 02:38:59
maerwald: So most (all?) XPath queries should be fairly trivial to write
maerwald 2017-03-08 02:39:15
not interested in that kind of oddity
quchen_ 2017-03-08 02:39:31
spatial: It's basically single-branch »if«, as long as you're in an Applicative context.
Aruro 2017-03-08 02:39:41
is brew install ghc a trap? takes hours to compile.
merijn 2017-03-08 02:39:58
Aruro: Why are you compiling? Why aren't you installing a binary distribution?
spatial 2017-03-08 02:40:04
But this is a simple 'if'
Aruro 2017-03-08 02:40:09
i just did brew install ghc
merijn 2017-03-08 02:40:11
Aruro: In short, yes that's a trap
Aruro 2017-03-08 02:40:19
wanted to be SMART.
merijn 2017-03-08 02:40:21
Aruro: I don't use brew, so I dunno wtf they do
spatial 2017-03-08 02:40:31
I have no idea what Applicative is.
Aruro 2017-03-08 02:40:43
they have 8.0.2 compiling from source
quchen_ 2017-03-08 02:40:45
spatial: Oh. Well, IO is an example of one. In IO, you can use »when«.
merijn 2017-03-08 02:40:48
Aruro: There's https://ghcformacosx.github.io/ but that's 7.10
maerwald 2017-03-08 02:40:53
guess this is another case of: try to find a useful library in haskell, realize there are only two options: 1. libraries that lack almost all required functionality to do a real-world project, 2. libraries that are just DSLs with a sh*tload of complexity, requiring you to invest more time than is useful
quchen_ 2017-03-08 02:41:01
spatial: Hold on a second.
Aruro 2017-03-08 02:41:06
which takes more than 3 hours, im getting ready for 8 hours compiling
kuribas 2017-03-08 02:41:07
spatial: it's more general as Monad. You can substitue Monad for it.
merijn 2017-03-08 02:41:09
Aruro: There's also stack (never used it), or just manually installing the GHC bindist from the GHC website
merijn 2017-03-08 02:41:25
Aruro: Compiling a release GHC is slow, yes. It needs to bootstrap
Aruro 2017-03-08 02:41:31
merijn: perhaps i had to install via stack, there is haskell-stack formula
spatial 2017-03-08 02:41:45
But even if loops are Monads in Haskell :-)
Aruro 2017-03-08 02:41:49
so 4 hours in i give up? :)
cris_ 2017-03-08 02:41:51
hi , i write up a library an upload to git , but i am not sure if the structure is right, as i could not import all of them in ghci, see https://github.com/szehk/Haskell-Carbonara-Library/blob/master/src/Data/Carbonara.hs
quchen_ 2017-03-08 02:42:49
spatial: Loops aren't monads. (I don't think the statement makes much sense.)
cris_ 2017-03-08 02:42:49
i intended to use /src/Data/Carbonara.hs to load all the other modules, not sure if this file is correct
quchen_ 2017-03-08 02:42:59
spatial: In IO, you have a value that just does nothing: »pure ()«.
quchen_ 2017-03-08 02:43:09
It's a NOOP that does nothing but return »()«.
quchen_ 2017-03-08 02:43:16
You can use that to do nothing.
spatial 2017-03-08 02:43:22
Yes
quchen_ 2017-03-08 02:43:33
Sooo: if a == 0 then putStrLn "hello" else pure ()
quchen_ 2017-03-08 02:43:40
This will print if a is 0, and do nothing otherwise.
spatial 2017-03-08 02:43:54
() should be in else ?
quchen_ 2017-03-08 02:44:00
»when« is a convenience definition for this,
cris_ 2017-03-08 02:44:01
my system is Slackware 14.2 + nixpkgs
quchen_ 2017-03-08 02:44:08
when (a == 0) (putStrLn "hello")
spatial 2017-03-08 02:44:39
So this if loop is wrong ?
quchen_ 2017-03-08 02:44:50
If loop?