Search Haskell Channel Logs

Sunday, February 19, 2017

#haskell channel featuring monochrom, enthropy, xcmw, kadoban, peddie, ReinH, and 5 others.

ReinH 2017-02-19 15:48:03
roconnor: fwiw, the report uses that wording
pyon 2017-02-19 15:48:34
roconnor: (+) is a defined constant... in a(n admittedly very common) context. Without that context, it seems to me that it's fair to say it appears free in the expression you gave.
ReinH 2017-02-19 15:50:11
roconnor: e.g., in Chapter 3 they write, "Free variables and constructors used in these translations always refer to entities defined by the Prelude."
ReinH 2017-02-19 15:50:11
(https://www.haskell.org/onlinereport/haskell2010/haskellch3.html)
roconnor 2017-02-19 15:53:36
pyon: yes.
pyon 2017-02-19 15:55:46
Could anyone please tell me why I get a stack overflow when running this code? https://gist.github.com/eduardoleon/89937fc083e69f50e70e76b1fd8718b3 (Ignore the SML version, it's just the same program, minus the QuickCheck test.)
pyon 2017-02-19 15:58:33
Alternatively, how can I get QuickCheck to produce a sample of values from a type, and just return that sample, without testing anything on it?
hpc 2017-02-19 15:59:22
for the second question, look at the operations on Gen
Koterpillar 2017-02-19 15:59:22
pyon: http://hackage.haskell.org/package/QuickCheck-2.9.2/docs/Test-QuickCheck-Gen.html#v:generate ?
pyon 2017-02-19 15:59:38
Ah, thanks!
pyon 2017-02-19 16:02:10
Ah, the problem is with my generator, not with the code being tested.
pyon 2017-02-19 16:02:31
Perhaps I shouldn't use generics as a replacement for thinking. :-|
xcmw 2017-02-19 16:07:06
Is it bad to use & and <&> instead of $ and <$>? I never see any programs wirtten with & and <&> but that style is easier to read for me.
kadoban 2017-02-19 16:07:56
xcmw: It's ... unusual.
kadoban 2017-02-19 16:08:17
You should get used to reading the other way for sure. Which one you actually use probably depends, I'd probably default to what everyone else does though.
peddie 2017-02-19 16:08:41
xcmw: if you consider that an important aspect of programs is having people read them, it might make sense to go with the flow
kadoban 2017-02-19 16:09:05
I use a flipped version of (.) and (&) in some coding contexts, but I'd never do it for like a library I'm publishing.
kadoban 2017-02-19 16:10:10
Or code I'm asking questions on or anything I hoped someone would read.
xcmw 2017-02-19 16:11:00
I find [1,2,3] <&> (+3) & filter (>4) easier to read than filter (>4) . map (+3) $ [1,2,3]
kadoban 2017-02-19 16:11:22
Keep using the common way until you can read either.
kadoban 2017-02-19 16:12:56
I don't really see how it could be that much harder to read though, you just start at the right instead of the left. Otherwise really no different. Only reason I use flipped (.) sometimes is ease of typing quickly, don't have to type backwards when I'm thinking forwards from the input.
xcmw 2017-02-19 16:16:11
kadoban: I have to mentally reorder it to read it
xcmw 2017-02-19 16:19:25
Is there a program that can automatically switch between styles?
kadoban 2017-02-19 16:19:38
If you keep practicing at it, it'll become natural.
Koterpillar 2017-02-19 16:19:50
xcmw: you can hack something out of hlint, I suppose
kadoban 2017-02-19 16:20:04
Can hlint automatically change code?
kadoban 2017-02-19 16:20:25
Oh it can, huh. How did I never know that.
monochrom 2017-02-19 16:20:36
Yikes
kadoban 2017-02-19 16:20:49
That sounds a bit scary though.
kadoban 2017-02-19 16:21:27
Looks like --refactor, unless I'm misunderstanding what that does.
enthropy 2017-02-19 16:23:10
I have a groupish function http://lpaste.net/352742 . Is there some way to write it in terms of sort/sortBy?
xcmw 2017-02-19 16:23:34
kadoban: "when I'm thinking forwards from the input" When do you think backwards from the input?
kadoban 2017-02-19 16:23:47
xcmw: The alternative would be backwards from the output.
xcmw 2017-02-19 16:24:05
kadoban: That is what I meant
kadoban 2017-02-19 16:24:26
Pretty rarely, but it happens. Can't say I can think of an example.
monochrom 2017-02-19 16:24:33
English is backwards from the input. The square root of the sine of x.
Koterpillar 2017-02-19 16:25:48
enthropy: I have a feeling you need to zip the 2nd and 3rd arguments first, then apply groups
xcmw 2017-02-19 16:27:27
monochrom: English is both
enthropy 2017-02-19 16:29:51
Koterpillar, by groups you mean Data.List.group?
Koterpillar 2017-02-19 16:30:39
yes
Koterpillar 2017-02-19 16:30:57
can you show some examples with groupish id?
Koterpillar 2017-02-19 16:31:18
i.e. is groupish id x y === x?
enthropy 2017-02-19 16:32:08
no, == y
Koterpillar 2017-02-19 16:33:05
that does not typecheck
Koterpillar 2017-02-19 16:33:19
because groupish id :: [a] -> [b] -> [a]
enthropy 2017-02-19 16:33:48
works in my ghci
kadoban 2017-02-19 16:34:02
Oh, I see what that function does. That was very confusing initially.
Koterpillar 2017-02-19 16:34:53
oh, sorry
Koterpillar 2017-02-19 16:34:59
groupish id :: [a] -> [a] -> [a]
Koterpillar 2017-02-19 16:37:26
I very much suspect that groupish f x y = map (map fst) $ group (\(x, y) -> f x == y) x y
Koterpillar 2017-02-19 16:37:49
but I haven't read the definition, only the type and examples
enthropy 2017-02-19 16:37:53
I might describe it as "groupish getB as bs" reorders `as` such that "map getB as == bs", and keep the ordering from `as`"
Koterpillar 2017-02-19 16:38:06
ooh
Koterpillar 2017-02-19 16:38:22
enthropy: groupish id [1, 1, 1] [2, 2, 2]
enthropy 2017-02-19 16:41:36
that's an error right now, but I think some idea of parametricity suggests it might be allowed to be [1,1,1]
enthropy 2017-02-19 16:42:39
I mean it would be a type error to put any 2 from the `bs` argument in the output
Koterpillar 2017-02-19 16:43:10
then it's a stable sort
Koterpillar 2017-02-19 16:43:29
by (index in bs . getB)
Koterpillar 2017-02-19 16:43:40
:t indexOf
lambdabot 2017-02-19 16:43:42
error:
lambdabot 2017-02-19 16:43:42
• Variable not in scope: indexOf
lambdabot 2017-02-19 16:43:42
• Perhaps you meant one of these:
Koterpillar 2017-02-19 16:43:43
:t index
lambdabot 2017-02-19 16:43:45
Ix a => (a, a) -> a -> Int
enthropy 2017-02-19 16:43:54
:t elemIndex
lambdabot 2017-02-19 16:43:56
Eq a => a -> [a] -> Maybe Int