zennist 2017-02-24 06:50:53
question again: can you implement 'unzip' via traverse
zennist 2017-02-24 06:51:41
i got this working by: traverse (\(a, b) -> ([a], b))
zennist 2017-02-24 06:51:48
but don't think very satisfactory
dolio 2017-02-24 06:53:29
You can implement map with traverse, and unzip is a combination of map fst and map snd.
monochrom 2017-02-24 06:54:13
Neat.
zennist 2017-02-24 06:54:30
well the output structure is different, so it's not just fold
zennist 2017-02-24 06:55:00
not just *map*
zennist 2017-02-24 06:55:27
although you can do it with just folding
dolio 2017-02-24 06:56:10
Yes, you can also do that.
zennist 2017-02-24 06:56:56
didn't try it out, but you should be able to write: unzip = foldMap (bimap pure pure)
zennist 2017-02-24 06:58:00
but obviously a naive implementation of foldMap means we go through the list twice
zennist 2017-02-24 06:58:11
sorry - no, my fault
c_wraith 2017-02-24 06:58:54
the problem with naive unzip is that it's spine-strict in the list.
shapr 2017-02-24 06:59:40
Aw, aku left
zennist 2017-02-24 07:00:23
which 'naive unzip' you are referring to?
c_wraith 2017-02-24 07:00:49
just about any unzip that isn't very careful with laziness.
drostie 2017-02-24 07:01:19
yeah the (Monoid a, Monoid b) => Monoid (a, b) instance is definitely where I'd be going with that.
drostie 2017-02-24 07:02:04
foldMap (bimap pure pure) should indeed get you there.
dolio 2017-02-24 07:02:34
That one might not be lazy enough.
dolio 2017-02-24 07:02:41
Not sure.
c_wraith 2017-02-24 07:02:53
yeah, I worry about mappend for that instance.
drostie 2017-02-24 07:05:21
You're right.
drostie 2017-02-24 07:05:33
let t10 (x, y) = (take 10 x, take 10 y)
zennist 2017-02-24 07:06:04
mhh imagine it's just (a, b) <> (c, d) = (a <> c, b <> d);; why is tup1 <> tup2 <> tup3 would cause the evaluation of the insides..? (I'm not good with laziness analysis) ; wouldn't it stop at the toplevel (<>) operator?
drostie 2017-02-24 07:06:09
t10 . unzip $ zip [1..] [0..] completes, t10 . foldMap (bimap pure pure) $ zip [1..] [0..] doesn't.
c_wraith 2017-02-24 07:07:02
zennist, you want to watch for forcing the (,) constructor in the second argument.
dolio 2017-02-24 07:07:03
Right, it'd need to be at least (a, b) <> ~(c, d) = (a <> c, b <> d)
zennist 2017-02-24 07:07:36
i see
zennist 2017-02-24 07:07:41
makes sense
drostie 2017-02-24 07:08:00
zennist: suppose we define `data Right x = E | R x` and then `instance Monoid Right where mempty = E, mappend (R x) y = case y of E -> R x; R z -> R z`
dolio 2017-02-24 07:08:13
It's not hard to write unzip correctly without thinking about it, though.
dolio 2017-02-24 07:08:16
Depends on your habits.
drostie 2017-02-24 07:08:53
zennist: foldMap doesn't know that that's not your monoid, and that monoid needs to have all the list information present before it can give you an answer. I think.
dolio 2017-02-24 07:08:55
If you always reach for case, you won't. If you prefer let instead, you will.
c_wraith 2017-02-24 07:09:17
I'd you write it correctly without thinking about it, it was an accident. :)
dolio 2017-02-24 07:09:58
Just like if you write it wrong without thinking about it.
zennist 2017-02-24 07:10:01
okay logically it makes sense; but on the detail level - say t10 forces the (,) constructor, but wouldn't the x, y arguments still stay as unevaluated thunks? then the take 10 x and take 10 y can do their magic
c_wraith 2017-02-24 07:10:10
dolio, I agree!
zennist 2017-02-24 07:10:38
i'd imagine at the point of calling t10, x and y are just tons of builds ups of 1<>2<>3<>....?
shapr 2017-02-24 07:10:46
byorgey: thanks for the link to that Jeremy Gibbons paper, I should just subscribe to his RSS publications feed.
c_wraith 2017-02-24 07:11:08
zennist, the problem is how much work needs to be done before producing the result (,) constructor
dolio 2017-02-24 07:11:09
zennist: t10 isn't a recursive function.
zennist 2017-02-24 07:11:58
c_wraith: wow, that's a brilliant way of thinking
c_wraith 2017-02-24 07:12:35
zennist, I wrote an answer on SO that applies here.. http://stackoverflow.com/questions/42150614/why-is-the-lazy-pattern-match-version-of-splitat-function-faster/42151076#42151076
c_wraith 2017-02-24 07:12:50
zennist, that may provide more detail, if you want it.
shapr 2017-02-24 07:12:57
Aha, so it's Carl_wraith
c_wraith 2017-02-24 07:13:05
my secret code!
c_wraith 2017-02-24 07:13:11
broken forever!
shapr 2017-02-24 07:13:15
:-)
zennist 2017-02-24 07:13:56
haha
zennist 2017-02-24 07:14:04
thanks guys - learned something today
drostie 2017-02-24 07:24:03
Ah c_wraith, I see what you were saying. Took me a second. Restating in my own words: the instance `mappend (a, b) (c, d) = (a <> c, b <> d)` is strict in both arguments because it pattern matches on both of them, so even though foldr is lazy in general foldr mappend mempty for this instance needs to destruct every single tuple in the input list. Is that about right?
c_wraith 2017-02-24 07:24:44
drostie, yes indeed. that's exactly it.
drostie 2017-02-24 07:24:56
(And `foldMap f` is just `foldr mappend mempty . map f` in this case hence the result applies to foldMap too.)
c_wraith 2017-02-24 07:27:43
this is a case where there are unfortunate choices to be made. some applications of mappend for tuples want that strictness. some do not.
c_wraith 2017-02-24 07:28:29
the best we can really manage is utility newtypes for this sort of thing, I think.
kmelva 2017-02-24 07:29:55
any selenium/webdriver users here? How to reuse an already open session in my tests?
kmelva 2017-02-24 07:30:21
trying to use REPL to write tests, but have no clue how to reuse an already open session... nothing in the webdriver docs that helps :/
Jello_Raptor 2017-02-24 07:31:34
Can someone help me understand this tweet? https://twitter.com/parametricity/status/558492726178881537
byorgey 2017-02-24 07:32:19
shapr: you can't go far wrong subscribing to anything by Jeremy Gibbons.
Jello_Raptor 2017-02-24 07:32:27
It's a joke, and it looks like the function is like Profunctor.lmap with a context.
dmwit 2017-02-24 07:33:25
I suspect that type is not implementable.
byorgey 2017-02-24 07:33:36
Jello_Raptor: sounds to me like you already understand the tweet.
Jello_Raptor 2017-02-24 07:33:40
oh nevermind, I can see a practical example of how you'd use it, at least if you change the constraint to `Monad f => ...`
Jello_Raptor 2017-02-24 07:34:12
byorgey: yeah :P it took me a bit though
byorgey 2017-02-24 07:34:24
the type is definitely not implementable with only Profunctor and Functor constraints.
Jello_Raptor 2017-02-24 07:34:33
oh?
dmwit 2017-02-24 07:34:41
e.g. specializing `f` to `[]` and `p` to `->`, we would get `(a -> [b]) -> (b -> r) -> [a -> r]` which... seems unlikely.
Jello_Raptor 2017-02-24 07:34:54
byorgey: how'd you go about showing that?
byorgey 2017-02-24 07:35:58
Jello_Raptor: to prove it formally? I dunno, something something parametricity something. But intuitively, all you can do is map stuff, there's no way to pull an f across the p like that.
dmwit 2017-02-24 07:36:27
right
byorgey 2017-02-24 07:36:49
or give a counterexample as dmwit has done. You could probably come up with an even simpler counterexample and give a proof by cases that no such function can exist.
Jello_Raptor 2017-02-24 07:37:04
byorgey: ahh, yeah the intuitive explanation was all I'm looking for. Is there a `class Profunctor p => ??? p` which would let you do that?
byorgey 2017-02-24 07:37:07
though to be completely formal it will still ultimately depend on parametricity.
dolio 2017-02-24 07:37:08
Probably don't need parametricity.
byorgey 2017-02-24 07:37:24
Jello_Raptor: I don't know. Good question.
dolio 2017-02-24 07:37:25
Just choose the right values for the variables and get a contradiction.
byorgey 2017-02-24 07:37:40
dolio: hmm, you're probably right
byorgey 2017-02-24 07:37:58
ah, yeah, showing that no such function can exist is easier than showing that all such functions must have property P
dolio 2017-02-24 07:38:01
Or something that can only be bottom in Haskell's case, I guess.
Jello_Raptor 2017-02-24 07:38:10
dmwit: right :/ that type really doesn't make sense.
dmwit 2017-02-24 07:38:27
The beauty of `Functor` is that it's such a weak constraint that practically everything is a `Functor`. The downside is that you can hardly do anything if all you know is `Functor`. Ditto with `Profunctor` everywhere.
Jello_Raptor 2017-02-24 07:38:52
all: i looks like I didn't get the joke, or at least one of the jokes, thanks :)
dmwit 2017-02-24 07:39:13
I think you got it just fine.
dmwit 2017-02-24 07:39:56
They're simultaneously roasting the "don't need docs because types" attitude and the "let's have lots of operators" attitude. The fact that their joke type isn't implementable is just icing on the already delicious cake.
Jello_Raptor 2017-02-24 07:40:09
dmwit: didn't realize the unimplementability :P the other bits I got
dmwit 2017-02-24 07:40:21
right
mauke 2017-02-24 07:41:33
> let foo :: (a -> [b]) -> (b -> r) -> [a -> r]; foo _ _ = [] in ()
lambdabot 2017-02-24 07:41:36
()
dolio 2017-02-24 07:41:47
dmwit: Is the joke that you figured out what it does just by looking at the type?
dmwit 2017-02-24 07:42:42
mauke: Yeah. The thing is we want an implementation of the concrete type that only uses things available to all Functor/Profunctor's.
dmwit 2017-02-24 07:44:24
Which... `[]` isn't.
Jello_Raptor 2017-02-24 07:45:16
unrelatedly I've got a hacky thing I'm using to get better error messages for a project of mine, but there's got to be an actual pattern for this sort of thing: http://lpaste.net/352946
Jello_Raptor 2017-02-24 07:45:16
This is mostly just a kludge for time reasons, but I'd like to know what I should be doing instead.
kmelva 2017-02-24 07:50:59
here it is: http://stackoverflow.com/questions/42446192/reuse-existing-selenium-session-with-haskell-and-webdriver ... if anyone has an idea, hit me :)
Jello_Raptor 2017-02-24 07:52:32
dmwit: cool, annotated source locs would be very nice. Thanks. Though i don't see a way to append Human readable metadata to the call stack. Which would allow me to use it as a more general error message mechanism.
Sonolin 2017-02-24 08:11:24
j
Sonolin 2017-02-24 08:11:54
sorry, I think I need a filter on my irc for vim keys...
Jello_Raptor 2017-02-24 08:24:25
Does anyone know why the haskell spec doesn't allow for infix operators with normal characters in them? something like `var_op ::= infix_char ([infix_char,alphaNum]*infix_char)?` so that the parser can tell operators apart since the first and last char of the operator is from the current set of allowed chars, but internal characters can come from the full range?
Jello_Raptor 2017-02-24 08:24:43
I'm just curious about the reasoning since, in many cases, operators like `` or whatnot would let us have nice oeprators with a much lower cost for readability
Jello_Raptor 2017-02-24 08:25:25
also, the fact that we can have `.<.` `.>.` `.^.` but not `.v.` annoys me
Tuplanolla 2017-02-24 08:25:45
Then people would have to separate tokens with spaces like civilized human beings.
Tuplanolla 2017-02-24 08:25:50
Can't have that.
Jello_Raptor 2017-02-24 08:25:55
:|
Jello_Raptor 2017-02-24 08:25:59
seriously?
Jello_Raptor 2017-02-24 08:27:06
literally the only place where that even makes a tiny amount of sense is composing lenses and even then only if you insist on making it look like record update syntax in more imperative languages.
Jello_Raptor 2017-02-24 08:27:17
or well, the only place I've seen where it makes sense.
taktoa 2017-02-24 08:27:19
Jello_Raptor: use the "binary or symbol"
Tuplanolla 2017-02-24 08:27:33
Consider the excited spectator operator `\o/` for example.
taktoa 2017-02-24 08:27:40
lol
Tuplanolla 2017-02-24 08:27:58
Suddenly everyone who writes `\x -> x` instead of `\ x -> x` would have broken programs on their hands.
Jello_Raptor 2017-02-24 08:27:58
taktoa: I add spaces around `||` <_<
Tuplanolla 2017-02-24 08:28:05
I wouldn't mind that, but I know some people would.
taktoa 2017-02-24 08:28:24
no I meant the unicode symbol that looks like "v"
taktoa 2017-02-24 08:28:59
http://www.fileformat.info/info/unicode/char/2228/index.htm
Jello_Raptor 2017-02-24 08:29:37
ahh yeah, problem is that unicode symbols require more special pleading to be useful. You have to set up your dev environment to support it. I'd much rather stick to standard ascii when possible. So that I'm not adding additional hurdles for other people working on my projects.
taktoa 2017-02-24 08:31:53
ah, true. as an emacs user I have a weird perspective on that ;^)
monochrom 2017-02-24 08:32:24
No, consider the excited robot operator \∩/
taktoa 2017-02-24 08:33:09
I definitely agree that a more Agda-like perspective on Haskell tokens would be nice
taktoa 2017-02-24 08:33:09
maybe even just with a language pragma
cdidd 2017-02-24 08:34:40
Is there a programming language with strict evaluation, full type inference for core language subset, and with parametric polymorphism/type clases/higher kinded types ?
monochrom 2017-02-24 08:39:45
probably Idris
cdidd 2017-02-24 08:40:28
monochrom, I thought you need to annotate everything with types in Idris. No?
monochrom 2017-02-24 08:40:40
Ah, nevermind.