Search Haskell Channel Logs

Thursday, January 26, 2017

#haskell channel featuring wonder01, qmm, dolio, dmwit, abhiroop, EvanR, and 13 others.

johndcl 2017-01-26 09:45:14
Hi. Can I bind keyboard shortcuts in ghci? For example I'd like to bind Ctrl-M to :reload.
johndcl 2017-01-26 09:45:25
:reload
EvanR 2017-01-26 09:47:56
Miroboru_: iterpreting the question literally, it may never get evaluated
EvanR 2017-01-26 09:48:18
take 100000 primes passed as an argument or not might never do anything
EvanR 2017-01-26 09:48:33
so the question is what your function is doing
Miroboru_ 2017-01-26 09:49:14
Well, it basically does "p `elem` plist" at different places
Miroboru_ 2017-01-26 09:49:33
To check if p is a prime
dmj` 2017-01-26 09:49:50
johndcl: don't think so, but haskell-mode for emacs does that with C-c C-l
Miroboru_ 2017-01-26 09:50:58
That is why I need to to truncate it ( I haven't found a good alternative to elem that takes into consideration the fact that plist is sorted.)
Miroboru_ 2017-01-26 09:52:06
Anyway - I suspect plist is lazily evaluated every time it is used like this ("p `elem` plist")
kadoban 2017-01-26 09:52:20
Miroboru_: If you need to do many queries of "is this prime?" you should probably be using something other than a list. A Set would work, or an IntSet will be faster, or an Array, which you can binary search in.
kadoban 2017-01-26 09:53:04
Miroboru_: If you have named plist at the top level, its value will be computed at most once.
Miroboru_ 2017-01-26 09:53:08
kadoban: Ok, thanks - I will refer to the documentation of this datastructures
qmm 2017-01-26 09:53:16
it is -1.6931471805599454
qmm 2017-01-26 09:53:26
how can i say 2 ^ it
qmm 2017-01-26 09:53:40
Could not deduce (Integral b0) arising from a use of '^'
kadoban 2017-01-26 09:53:42
Miroboru_: Also, how are you generating the primes list? That can be done *very* slowly, or quite quickly, depending on how you're doing it.
qmm 2017-01-26 09:53:55
i'll think about this a little more
Miroboru_ 2017-01-26 09:54:12
I am using a proper sieve of erasthotenes (http://www.garrisonjensen.com/2015/05/13/haskell-programs-are-lies.html)
geekosaur 2017-01-26 09:54:14
qmm, there's 3 different exponentiation operators
geekosaur 2017-01-26 09:54:18
:t (^)
lambdabot 2017-01-26 09:54:20
(Num a, Integral b) => a -> b -> a
geekosaur 2017-01-26 09:54:23
:t (^^)
lambdabot 2017-01-26 09:54:25
(Integral b, Fractional a) => a -> b -> a
geekosaur 2017-01-26 09:54:29
:t (*)
lambdabot 2017-01-26 09:54:31
Num a => a -> a -> a
geekosaur 2017-01-26 09:54:35
er
mmaruseacph2 2017-01-26 09:54:35
til about (^^)
geekosaur 2017-01-26 09:54:38
:t (**)
lambdabot 2017-01-26 09:54:40
Floating a => a -> a -> a
geekosaur 2017-01-26 09:54:42
that one
wonder01 2017-01-26 09:54:46
The solver for my stack project is 7.16. I want to use alex-3.2.1, however alex-3.1.7 is in the lts-7.16 snapshot.
wonder01 2017-01-26 09:55:08
The error I'm getting is setup: The program 'alex' version >=3.2.1 is required but the version found at /home/me/.stack/snapshots/x86_64-linux/lts-7.16/8.0.1/bin/alex is version
geekosaur 2017-01-26 09:55:09
wonder01, you'd need to list the later version in extra-deps in stack.yml
geekosaur 2017-01-26 09:55:26
so it overrides the resolver
qmm 2017-01-26 09:55:32
geekosaur: helpful! thank you
kadoban 2017-01-26 09:55:34
Miroboru_: Ah. That's also available, a better one I believe, in the 'primes' package. A better writeup is https://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
EvanR 2017-01-26 09:55:50
Miroboru_: elem traverse the list from the beginning and checks each item for equality
EvanR 2017-01-26 09:55:55
thats why its slow
EvanR 2017-01-26 09:56:23
if its also recomputing the primes list each time, its even slower
EvanR 2017-01-26 09:56:29
whether it does depends
geekosaur 2017-01-26 09:56:39
wonder01, https://docs.haskellstack.org/en/stable/yaml_configuration/#local-dependency-packages-extra-dep
wonder01 2017-01-26 09:57:08
geekosaur: I have:
wonder01 2017-01-26 09:57:12
extra-deps: - alex-3.2.1
kadoban 2017-01-26 09:57:46
wonder01: Good. It's usually on separate lines, but I don't know if it needs to be. It might.
wonder01 2017-01-26 09:58:03
It is on separate lines (copy/paste rendering)
geekosaur 2017-01-26 09:58:11
I think it does
geekosaur 2017-01-26 09:58:17
yaml is ... interesting
geekosaur 2017-01-26 09:58:26
and I poitned to the wrong thing (s/b https://docs.haskellstack.org/en/stable/yaml_configuration/#extra-deps) but you're using the right one
Miroboru_ 2017-01-26 09:58:33
EvanR: Yes - I need to redo this a bit - just doing some project Euler problems (http://projecteuler.net/) to learn myself some Haskell, and I thought I would get away with doing it very quick and dirty... No such luck :)
geekosaur 2017-01-26 09:58:36
so, I don't know
Miroboru_ 2017-01-26 10:00:01
kadoban: Thanks - I know the paper, and I think the code I linked to is based on this. Anyway, I'd rather use a proper Haskell package. I'll have a look at the primes package
kadoban 2017-01-26 10:00:46
I suspect the code you linked is based on it, but not using the optimal data structure.
kadoban 2017-01-26 10:00:53
I didn't look too close though.
johndcl 2017-01-26 10:03:43
dmj`: I put 'bind: ctrl-o : r return' line in ~/.haskeline. For some reason I couldn't rebind ctrl-m.
glguy 2017-01-26 10:04:20
johndcl: ^M is the enter key
johndcl 2017-01-26 10:04:47
I hoped I could rebind it since I have Enter on my keboard. :o)
glguy 2017-01-26 10:05:23
from the terminal's point of view they're the same thing
dolio 2017-01-26 10:07:28
Yeah, at the level haskeline sits, I don't think it's possible to detect the difference.
dfeuer 2017-01-26 10:08:06
dmwit: does your Exists thing have any useful instances?
geekosaur 2017-01-26 10:08:42
johndcl, it's not possible; you need to use a GUI event interface to see the difference
dfeuer 2017-01-26 10:09:23
dolio: Did you see my message about traversing roots and leaves? I figured you might be the one who would have thoughts.
dolio 2017-01-26 10:09:47
I haven't.
dfeuer 2017-01-26 10:10:41
dolio: if you define `traverse` for a tree, you'll typically end up with a lot of fmap happening in the leaves. You can generally avoid it by doing a lot of extra pattern matching, but it's obnoxious.
dfeuer 2017-01-26 10:11:01
I'd love to find a fix.
qmm 2017-01-26 10:22:50
how would i say create a new list which subtracts the last number from the current number given a list like [10..1]
koala_man 2017-01-26 10:23:35
[10,9..1]
qmm 2017-01-26 10:23:41
koala_man: thanks
qmm 2017-01-26 10:24:27
the first element would be subtracted by a number to start with
qmm 2017-01-26 10:24:32
the second would be 10 -9
qmm 2017-01-26 10:24:37
third would be 9 -8
qmm 2017-01-26 10:24:45
9 - 8 --not negative
qmm 2017-01-26 10:24:57
surely i can think of this without resorting to #haskell for answers :)
qmm 2017-01-26 10:25:26
i'll ask later if i'm stumped
koala_man 2017-01-26 10:25:28
oh, you wanted [x,y,z] to become [x-y, y-z] ?
qmm 2017-01-26 10:25:34
right
qmm 2017-01-26 10:25:56
i immediately looked into foldr, but then it results in a single number instead of a list of them
qmm 2017-01-26 10:26:05
(brain fart)
kadoban 2017-01-26 10:26:14
> let xs = [1..10] in zipWith subtract xs (tail xs)
lambdabot 2017-01-26 10:26:17
[1,1,1,1,1,1,1,1,1]
kadoban 2017-01-26 10:26:19
That?
kadoban 2017-01-26 10:26:21
Wait ...
kadoban 2017-01-26 10:26:34
Well, maybe that's what you want, I dunno exactly.
qmm 2017-01-26 10:27:00
kadoban: i appreciate your help. i'll look at this channel a little later since i'm wanting to figure it out for myself right now
kadoban 2017-01-26 10:27:11
Fair enough, sorry.
koala_man 2017-01-26 10:27:30
kadoban: I think it is, except this gives you next-previous instead of previous-next
kadoban 2017-01-26 10:28:03
Ya, could be
koala_man 2017-01-26 10:28:15
> let xs = [5,3,2,2] in zipWith (-) xs (tail xs)
lambdabot 2017-01-26 10:28:17
[2,1,0]
koala_man 2017-01-26 10:28:26
5-3, 3-2, 2-2
dmwit 2017-01-26 10:29:48
dfeuer: Not many. `instance Show (Exists Show)` and similar serialization classes.
dmwit 2017-01-26 10:30:01
deserialization is harder =P
skeuomorf 2017-01-26 10:31:38
Are there books in the same vein as "The Haskell road to logic, ..." but dicsusses more advanced mathematical topics with the same level of Haskell expectations?
monochrom 2017-01-26 10:32:00
Such as general relativity? :)
skeuomorf 2017-01-26 10:32:46
i.e. takes the reader through learning Haskell while at the same time learning some mathematical branch?
skeuomorf 2017-01-26 10:32:57
monochrom: Sure, why not?
skeuomorf 2017-01-26 10:33:24
Even something in the vein of SICM but uses Haskell instead of scheme
dfeuer 2017-01-26 10:37:14
dmwit: hrmm... You can do a little better with the Show instance using Data.Constraint.Forall.
abhiroop 2017-01-26 10:40:00
I am trying to understand a piece of List Transformer code: http://lpaste.net/351676
abhiroop 2017-01-26 10:40:14
Can someone explain why this output came up. I mentioned my expected output in the file http://lpaste.net/351677
Zemyla 2017-01-26 10:42:11
If a Profunctor p is both Representable and Corepresentable, then Rep p and Corep p are adjoint, right?
dmwit 2017-01-26 10:45:06
dfeuer: do tell