Search Haskell Channel Logs

Thursday, January 26, 2017

#haskell channel featuring Koterpillar, dolio, dmwit, geekosaur, Xyliton, codedmart, and 13 others.

dfeuer 2017-01-26 10:48:21
dmwit: oh, sorry I vanished.
dfeuer 2017-01-26 10:48:50
dmwit: the gist is that if c a :- Show a, then Exists c should be Show, right?
dmwit 2017-01-26 10:50:04
Yes, but `c a :- Show a` is a term-level thing. So how do you use it in the `Show` instance?
dfeuer 2017-01-26 10:50:17
dmwit: give me a moment.
dmwit 2017-01-26 10:50:21
See also glguy's proposal for `Object` which solves this by writing `Show \in cs` as a type-level thing.
dfeuer 2017-01-26 10:51:00
I'm pretty sure I can do this, but I'll need to think a sec.
codedmart 2017-01-26 10:51:09
I am working on tracking changes to my data. I convert them toJSON and check that way. The problem is I started out pattern matching each case as I go and now I feel like this is way out of hand. Anyone have some suggestions for simplifying this: https://gist.github.com/codedmart/c28ed15d956b043033a6952689f021c3#file-activitylog-hs-L116-L143
codedmart 2017-01-26 10:51:34
This actually works just seems like to much to me.
dmwit 2017-01-26 10:52:18
codedmart: The thing to google for is "tree diff".
dmwit 2017-01-26 10:52:31
There's lots of information online about different ways to diff trees, with different tradeoffs.
codedmart 2017-01-26 10:52:57
dmwit: Are my assumptions right that this code is not good practice?
dmwit 2017-01-26 10:53:01
There's also http://hackage.haskell.org/package/gdiff
dmwit 2017-01-26 10:53:13
which you might like, but should be used without bothering with `toJSON`.
dfeuer 2017-01-26 10:53:42
dmwit: write class Show a => Q (c :: * -> Constraint) a; instance Show a => Q c a; instance (Forall (Q c)) => Show (Exists c) where ...
dmwit 2017-01-26 10:53:42
codedmart: Mine eyes glazeth over. That's usually a bad sign, but not always.
dfeuer 2017-01-26 10:54:08
It's not pretty, but I think it will work.
dfeuer 2017-01-26 10:54:26
Oh, no, that doesn't work.
dfeuer 2017-01-26 10:54:29
What am I thinking.
dfeuer 2017-01-26 10:54:35
Brain broke.
dfeuer 2017-01-26 10:54:45
Or ...
phadej 2017-01-26 10:54:46
codedmart: I used https://github.com/haskell/cabal/blob/master/Cabal/tests/StructDiff.hs
dfeuer 2017-01-26 10:54:53
Or does it?
phadej 2017-01-26 10:55:00
it works with generics-sop, and work'd well enough
phadej 2017-01-26 10:55:14
(compared Cabal GenericPackageDescription AST's with it)
dmwit 2017-01-26 10:55:58
dfeuer: Since there appears to be no connection between `c` and `Show` there, it seems unlikely that it means what we want it to mean.
dfeuer 2017-01-26 10:56:06
Yeeeeah.
dfeuer 2017-01-26 10:56:16
dmwit: give me another few minutes.
dfeuer 2017-01-26 10:56:24
I am confident I can do it another way.
dfeuer 2017-01-26 10:56:50
Moderately confident.
codedmart 2017-01-26 10:57:05
phadej: OK cool I will take a look.
codedmart 2017-01-26 10:57:07
Thanks guys
dfeuer 2017-01-26 10:58:11
Grr.
dmwit 2017-01-26 11:01:08
abhiroop: Did you get an answer?
dfeuer 2017-01-26 11:03:34
dmwit: actually, it works exactly like I said.
lpaste 2017-01-26 11:04:09
dfeuer pasted "Show Exists" at http://lpaste.net/351680
dfeuer 2017-01-26 11:04:18
dmwit: ^^
dfeuer 2017-01-26 11:04:29
At least, I think that works.
dfeuer 2017-01-26 11:04:34
Haven't actually tested it.
dmwit 2017-01-26 11:05:52
I severely doubt you can show `Forall (Q c)` for any interesting `c`.
dfeuer 2017-01-26 11:05:55
Oh, no, this is not working.
dmwit 2017-01-26 11:06:04
e.g. even `c ~ Show`
dfeuer 2017-01-26 11:06:14
Gah.
dmwit 2017-01-26 11:07:02
abhiroop: Can you explain why you expected the output you did? Perhaps I can help clear up where you've made a mistake.
dmwit 2017-01-26 11:09:37
dfeuer: You could imagine `class BetterThanShow c where betterThanShow :: c a :- Show a; instance BetterThanShow c => Show (Exists c)`.
dfeuer 2017-01-26 11:09:56
Yeah, but then you have trouble getting the instances.
dfeuer 2017-01-26 11:10:02
:(
dmwit 2017-01-26 11:10:18
Indeed, you have to write them.
dfeuer 2017-01-26 11:10:44
dmwit: whata's this proposal to fix the trouble?
dfeuer 2017-01-26 11:10:49
Where?
abhiroop 2017-01-26 11:11:51
([1,2],'a')
abhiroop 2017-01-26 11:11:51
([1,2],'b')
abhiroop 2017-01-26 11:11:56
dmwit: my expectation was owing to the fact that the function test will execute the first time and produce
dmwit 2017-01-26 11:12:22
abhiroop: So far, so good.
abhiroop 2017-01-26 11:12:35
and followed by that it will execute test again
abhiroop 2017-01-26 11:12:42
ignore the first test
dmwit 2017-01-26 11:12:46
This is your mistake.
abhiroop 2017-01-26 11:13:12
but now I am getting some surprising results
abhiroop 2017-01-26 11:13:45
I didn't expect [(),()]>>[10,20] to emit [10,20,10,20]
dmwit 2017-01-26 11:14:01
abhiroop: Yes, the two surprises are related. =)
dmwit 2017-01-26 11:14:58
abhiroop: You are thinking that `(>>)` ignores its first argument. But this is not true: it merely ignores the *values produced* by its first argument.
dmwit 2017-01-26 11:15:23
abhiroop: So for lists, this means `(>>)` ignores the values of the elements of the list you pass as the first argument. But it doesn't ignore the list entirely -- the size of the list is used!
Koterpillar 2017-01-26 11:15:30
if that were true, what would happen here: putStrLn "first" >> putStrLn "second" ?
abhiroop 2017-01-26 11:16:54
I am expecting "first" followed by "second" without the quotes of course
geekosaur 2017-01-26 11:17:24
but those are not results; the result is an IO ()
dmwit 2017-01-26 11:19:01
abhiroop: Consider this related action: `[1,2] >>= \x -> [10+x, 20+x]`. What do you expect to happen?
dmwit 2017-01-26 11:19:42
> [1,2] >>= \x -> [10+x, 20+x]
lambdabot 2017-01-26 11:19:43
[11,21,12,22]
dmwit 2017-01-26 11:19:49
Now this one:
dmwit 2017-01-26 11:20:00
> [1,2] >>= \x -> [const 10 x, const 20 x]
lambdabot 2017-01-26 11:20:04
[10,20,10,20]
dmwit 2017-01-26 11:20:07
should be no surprise
dmwit 2017-01-26 11:20:19
> [1, 2] >>= \x -> [10, 20]
lambdabot 2017-01-26 11:20:22
[10,20,10,20]
dmwit 2017-01-26 11:20:27
> [(), ()] >>= \x -> [10, 20]
lambdabot 2017-01-26 11:20:29
[10,20,10,20]
dmwit 2017-01-26 11:20:40
...which leads us to your example. =)
abhiroop 2017-01-26 11:21:02
wow that was a great example!
abhiroop 2017-01-26 11:21:11
thanks dmwit!
abhiroop 2017-01-26 11:21:17
aha moment
orzo 2017-01-26 11:33:49
So i've just discovered :sprint in ghci and I cannot seem to convince it to print anything other than "x = _" for a variablex
SpinTensor 2017-01-26 11:33:58
hi. I want to write a function that gets the first commandline argument if and only if exactly one is present. i tried this, but i don't understand it apearrently
SpinTensor 2017-01-26 11:34:13
http://pastebin.com/NWKxjp8e
glguy 2017-01-26 11:34:23
orzo: Well, what type does x have?
Ptival 2017-01-26 11:34:26
http://paste.awesom.eu/6lna does anyone know how to make workIt print Todo 1, Todo 10, Todo 2, Todo3
glguy 2017-01-26 11:34:33
orzo: and how did you define x?
orzo 2017-01-26 11:34:54
differnet ways, as a list at first
orzo 2017-01-26 11:35:04
just tell me something to try
glguy 2017-01-26 11:35:07
SpinTensor: You can't start guards after that first '='
orzo 2017-01-26 11:35:10
to see something different with spine
geekosaur 2017-01-26 11:35:14
SpinTensor, I am guessing from the []s that you are not in IO
glguy 2017-01-26 11:35:16
SpinTensor: You can use if then else, or you can use case of
glguy 2017-01-26 11:35:22
SpinTensor: In this case you want case of
Xyliton 2017-01-26 11:35:31
How would one work with 3D matrices in Haskell?
hpc 2017-01-26 11:35:42
orzo: import System.IO and use evaluate
hpc 2017-01-26 11:35:57
just kidding, Control.Exception
SpinTensor 2017-01-26 11:35:58
ok thanks. I try, and will come back to you
Tuplanolla 2017-01-26 11:36:02
Arrays or matrices, Xyliton?
glguy 2017-01-26 11:36:06
orzo: You can't hand-wave the answer, it matters what you wrote
hpc 2017-01-26 11:36:24
orzo: so you can do something like
hpc 2017-01-26 11:36:27
let x = Just 5
hpc 2017-01-26 11:36:29
evaluate x
hpc 2017-01-26 11:36:31
:sprint x
athan 2017-01-26 11:37:04
what would it look like if a behavior could affect the rate of time?
hpc 2017-01-26 11:37:08
but it matters what type x has, the value it has, and what operations you have performed on it
orzo 2017-01-26 11:37:10
hpc, do you mean Control.Exception.evaluate?
lpaste 2017-01-26 11:37:16
glguy pasted "for spin tensor" at http://lpaste.net/351681
hpc 2017-01-26 11:37:30
evaluation is sensitive to pretty much everything
Xyliton 2017-01-26 11:37:31
Tuplanolla: I want to "Circle Hough Transform" a picture and the wikipedia articles says that it needs a "3d parameter space" and a "3d accumulator matrix", su I suppose i need matrices
glguy 2017-01-26 11:37:47
hpc: Like in your example x has a polymorphic type, so sprint will always report _
hpc 2017-01-26 11:38:07
oh crap, right
hpc 2017-01-26 11:38:10
let x = Just False
orzo 2017-01-26 11:38:57
hpc, i tried your first example, let x = Just 5, evaluate x (it showed Just 5), :sprint x (it showed x = _)
Tuplanolla 2017-01-26 11:39:20
A Hough transform should only require ordinary matrices, so I guess `hmatrix`, Xyliton.
glguy 2017-01-26 11:39:39
orzo: Turn the monomorphism restrict back on, or give 'x' a monomorphic type
hpc 2017-01-26 11:39:39
orzo: let x = Just 5, then evalute (isJust x)
hpc 2017-01-26 11:40:28
argh, False is already in normal form
Tuplanolla 2017-01-26 11:40:31
If you just want arrays, there's `repa`, Xyliton.
hpc 2017-01-26 11:40:44
aha
hpc 2017-01-26 11:40:50
let x = Just (id False)
hpc 2017-01-26 11:40:51
:sprint x
MarcelineVQ 2017-01-26 11:40:54
orzo: another fun and direct example is a list with a concrete type like x = [1..10 :: Int] :spriint x take 2 x :sprint x
hpc 2017-01-26 11:41:08
it happens to already be in whnf because the root of the expression is a constructor
hpc 2017-01-26 11:41:25
and then id is used here to introduce laziness
hpc 2017-01-26 11:41:33
which is funny because id is technically a strict function
Xyliton 2017-01-26 11:42:06
Tuplanolla: I'm not sure what's easier. I only have a limited amount of knowledge about matrices
hpc 2017-01-26 11:42:39
(tested and working on my machine btw)
hpc 2017-01-26 11:43:08
orzo: and that's your first lesson in "strictness changes depends on anything and everything you do"
glguy 2017-01-26 11:43:28
The real lesson is on why the Monomorphism restriction is your friend
hpc 2017-01-26 11:43:46
that too
dolio 2017-01-26 11:44:10
No it isn't.
glguy 2017-01-26 11:44:31
Is too!
hpc 2017-01-26 11:44:33
it's also your enemy, but in this case it's a bit of a friend
hpc 2017-01-26 11:44:52
like frank in mash
hpc 2017-01-26 11:44:59
this is the episode where you almost feel sorry for him in one scene