Search Haskell Channel Logs

Monday, March 6, 2017

#haskell channel featuring GreySunshine, Tuplanolla, contiver_, sdrodge, lambdabot, dmwit, and 5 others.

contiver_ 2017-03-06 07:10:44
I just realized there is no liftA4, so I ended up using liftM4. Any particular reason for that?
bollu 2017-03-06 07:10:58
kuribas, geekosaur: how would I use ViewPatterns for this?
bollu 2017-03-06 07:11:09
contiver_: why not do-notation at that point? or <$> <*> … ?
geekosaur 2017-03-06 07:11:11
nobody thought it was needed? and liftA is just a chain of <$> ... <*> ... <*>
Tuplanolla 2017-03-06 07:12:35
We should totally have a `liftAN` splice for completeness.
bollu 2017-03-06 07:13:10
mnoonan: how do I ViewPatterns this?
kuribas 2017-03-06 07:13:14
I would write something like this: myFun closure | lf <- _closureLambda closure, _lambdaShouldUpdate lf == False = stepEnter... lf | otherwise -> error ...
contiver_ 2017-03-06 07:13:39
bollu: I could do that, but then I'd either have more lines, or it would go further to the right. In other words, just personal taste.
bollu 2017-03-06 07:13:58
contiver_: I think a ViewPattern would carry intent better?
contiver_ 2017-03-06 07:14:02
I just expected there would be a liftA4, being there a liftM4 already.
bollu 2017-03-06 07:14:05
contiver_: like, "this is a non updatable closure"
kuribas 2017-03-06 07:14:08
bollu: I'd only use a pattern synonym when I have the same pattern many times.
bollu 2017-03-06 07:14:14
kuribas: oh, I see
bollu 2017-03-06 07:14:16
kuribas: hm
bollu 2017-03-06 07:14:22
kuribas: I don't know how often this comes up
geekosaur 2017-03-06 07:14:27
contiver_, things like liftM4 are historical... and not very widely used
bollu 2017-03-06 07:14:28
I am implementing STG for understanding
bollu 2017-03-06 07:14:38
if quchen was around, he would know
geekosaur 2017-03-06 07:15:31
so there's a fair amount of "...do we really need this?", akin to how there's 15 tuple instances for any typeclass that can take a tuple and a;most nobody uses anything bigger than a 3-tuple or the occasional 4-tuple
geekosaur 2017-03-06 07:16:56
(historical = that was before someone figured out they could use liftM and `ap` instead of having to have umpteen different liftMn-s)
geekosaur 2017-03-06 07:17:18
(which was how we spelled <$> and <*> in the monad version, which predated Applicative by like a decade or so)
contiver_ 2017-03-06 07:17:35
geekosaur, yes, I get what you mean, monads came before than applicative, and hence both APIs share much.
geekosaur 2017-03-06 07:17:59
but more than that, liftMn for n > 2 is itself predating the generalized version
geekosaur 2017-03-06 07:18:13
whereas Applicative always had the generalized one
geekosaur 2017-03-06 07:18:51
and tbh I;ve never needed more than liftM3 / liftA3
bollu 2017-03-06 07:18:54
geekosaur: do you know the "actual" main type before IO? I am told it was [Input] -> [Output], but is that true?
geekosaur 2017-03-06 07:19:10
[Response] -> [Request]
kuribas 2017-03-06 07:19:18
bollu: there is filtered from lens, but it may not give a legal lens...
dmwit 2017-03-06 07:19:18
http://hackage.haskell.org/package/data-aviary-0.2.3/docs/Data-Aviary-Birds.html is pretty funny =)
geekosaur 2017-03-06 07:19:18
the initial Response had argv in it
kuribas 2017-03-06 07:19:20
:t filtered
lambdabot 2017-03-06 07:19:23
(Choice p, Applicative f) => (a -> Bool) -> Optic' p f a a
geekosaur 2017-03-06 07:19:31
among other things
bollu 2017-03-06 07:19:38
geekosaur: um, response to requests?
bollu 2017-03-06 07:19:45
geekosaur: explain that a bit please?
Tuplanolla 2017-03-06 07:20:00
The runtime system has the other order, bollu.
Tuplanolla 2017-03-06 07:20:10
It's like a server--client relationship.
geekosaur 2017-03-06 07:20:15
yes, you receive a Response from the OS (again, the initial one was the command line parameters) and produce Request-s to the OS for I/O. both were lazy lists
bollu 2017-03-06 07:20:22
ah
bollu 2017-03-06 07:20:24
dang
bollu 2017-03-06 07:20:26
that is quite cool
Tuplanolla 2017-03-06 07:20:36
Yeah, until you actually use it.
bollu 2017-03-06 07:20:37
is there some way to "go back" to that style of programming?
bollu 2017-03-06 07:20:38
xD
dmwit 2017-03-06 07:20:43
bollu: `Request` was an ADT with things like `PutStrLn :: String -> Request`, `GetLine :: Request`. `Response` was an ADT with things like `GotALine :: String -> Response`.
bollu 2017-03-06 07:20:45
Tuplanolla: what were the pain points?
Tuplanolla 2017-03-06 07:20:58
I didn't use Haskell back then.
geekosaur 2017-03-06 07:21:08
it's "cool" in the "neat hack" sense. I'd rather beat my head against a brick wall than actually *write* to it...
dmwit 2017-03-06 07:21:23
Pain points: your response consumption must be kept in synch with your request generation, or else you start reading responses to a different request than the one you sent.
sdrodge 2017-03-06 07:21:48
It's all fun and games until you accidentally force the input list too hard and get a deadlock.
dmwit 2017-03-06 07:21:54
Responses are completely untyped; even though you know `GetLine` should always respond with `GotALine s`, you still have to write a case that covers all possible responses.
bollu 2017-03-06 07:22:06
dmwit: hmm
kuribas 2017-03-06 07:22:23
What's a good debugging strategy? I find the ghci debugger rather painfull.
bollu 2017-03-06 07:22:55
dmwit: is there some way to emulate this in current haskell? short of writing a library
dmwit 2017-03-06 07:23:00
:t interact
lambdabot 2017-03-06 07:23:03
(String -> String) -> IO ()
kuribas 2017-03-06 07:23:08
Or use cpphs to conditionally produce debug output?
bollu 2017-03-06 07:23:09
interesting
bollu 2017-03-06 07:23:18
dmwit: that seems quite REPLy
geekosaur 2017-03-06 07:23:51
you could say it's an inside-out REPL
sdrodge 2017-03-06 07:33:32
btw, still looking for comments on how to improve this code: https://hastebin.com/jicequciqu.hs
sdrodge 2017-03-06 07:33:56
My solution feels very janky and hacked together, and I would appreciate the eyes of a more experienced haskeller.
geekosaur 2017-03-06 07:34:05
og feh, should have actually read the furst url, I was tryoing to keep up with too much and thought Dialogue refered to the prose part
dmwit 2017-03-06 07:36:51
sdrodge: http://hackage.haskell.org/package/multiset-0.3.3/docs/Data-IntMultiSet.html
dmwit 2017-03-06 07:38:29
Also, a very minor suggestion: `queries <- replicateM numQueries readLn`.
dmwit 2017-03-06 07:38:44
You should not need either type ascription.
sdrodge 2017-03-06 07:39:19
true, good point
dmwit 2017-03-06 07:40:20
If raw speed matters, `even` and `odd` can be replaced with `Data.Bits` operations.
dmwit 2017-03-06 07:40:39
(And computed once per call to `updateTrackers` instead of potentially four times.
dmwit 2017-03-06 07:40:42
)
dmwit 2017-03-06 07:41:11
Possibly: `updateTrackers n ts = case (compare n median, odd s) of ...` would be more idiomatic.
GreySunshine 2017-03-06 07:41:11
Hello, does ghc have a risc V port?
dmwit 2017-03-06 07:42:09
However, I haven't understood the algorithm well enough to be able to give deep advice; all of this is admittedly very superficial.
dmwit 2017-03-06 07:42:10
Apologies for that.
sdrodge 2017-03-06 07:42:22
dmwit: No problem. Still interesting suggestions.
thoughtpolice 2017-03-06 07:42:50
GreySunshine: People have worked on it, with the LLVM fork it's possible if you know what you're doing (people have gotten it working in RISC-V/QEMU). It's certainly not "officially supported" in any real sense while all the toolchains, etc are still being merged upstream and ironed out, however.
sdrodge 2017-03-06 07:43:28
dmwit: The high level overview of what is going on is that you're fed a series of integers, if they are positive, you should add them to the current set and recompute the median of the set, if they are negative, you should roll back the state by the corresponding amount (where -1 means repeat the state that we were just at).
f-a 2017-03-06 07:43:42
I am reading ye olde yampa paper. There is a datatype (Identity list) which reads: data IL a = IL { ilNextKey :: Int, ilAssocs :: [(Int, a)] }. Does it have a name? (And most importantly, does it have a package? List doesn't seem the most efficient way to implement it)
sdrodge 2017-03-06 07:44:16
dmwit: So I'm just tracking the state after each query as an IntMedianTracker in a sequence.
sdrodge 2017-03-06 07:44:46
Which gives me O(log n) new state creation and O(log n) access to previous states.
sdrodge 2017-03-06 07:44:56
Which is good enough because you get at most 10^5 queries.