Search Haskell Channel Logs

Thursday, January 26, 2017

#haskell channel featuring osa1, dramforever, uiop, liste, lambdabot, glguy,

orzo 2017-01-26 18:58:16
can i define a pattern synonym that matches (k,p,_) when used as a pattern, but (k,p,k) when used as data?
orzo 2017-01-26 19:09:53
pattern k :-> p <- (k,p,_) where k :-> p = (k,p,k)
orzo 2017-01-26 19:10:05
that's an attempt, but it gives a type error because it canot infer the _ is the right type
glguy 2017-01-26 19:12:06
orzo: pattern (:->) :: a -> b -> (a,b,a)
glguy 2017-01-26 19:12:06
pattern k :-> p <- (k,p,_) where k :-> p = (k,p,k)
orzo 2017-01-26 19:14:10
thanks
orzo 2017-01-26 19:14:23
first i was trying to get it to infer using a | guard
orzo 2017-01-26 19:14:29
it says syntax error
orzo 2017-01-26 19:14:36
i guess we cant put guards on pattern synonyms?
fragamus 2017-01-26 19:17:19
speaking of guards... I have a stream :: Shell Text and I want to put a guard on it
glguy 2017-01-26 19:19:14
orzo: Correct
glguy 2017-01-26 19:19:45
fragamus: go nuts
fragamus 2017-01-26 19:21:06
i tried. gabriel says Shell is a combination of list monad and IO and managed but it does seem to be a little more involved
liste 2017-01-26 19:22:14
:t guard
lambdabot 2017-01-26 19:22:16
Alternative f => Bool -> f ()
liste 2017-01-26 19:22:49
and Shell has an Alternative instance
osa1 2017-01-26 19:23:48
say I have two threads running `modifyMVar_ mvar (\a -> return (a + 1))` and mvar content is initailly 0, I can read 1 after both threads terminate, right?
glguy 2017-01-26 19:24:04
orzo was talking about (pipe) | guards on definitions, were you talking about that or the "guard" function, fragamus?
osa1 2017-01-26 19:24:14
the documentation says "only atomic if there's only one producer" and I'm guessing that's what it means
fragamus 2017-01-26 19:24:39
yes the guard function
glguy 2017-01-26 19:24:59
osa1: It would be atomic
glguy 2017-01-26 19:25:07
There's only one producer, the initial newMVar
glguy 2017-01-26 19:25:33
modifyMVar_ blocks until it's able to take the mvar and puts it back when done
glguy 2017-01-26 19:25:59
It takes before it puts, so it doesn't compromise your atomicity
osa1 2017-01-26 19:26:27
glguy: got it, thanks. I'm a bit confused about what does "atomic" in this context (in the documentation) means
uiop 2017-01-26 19:26:30
so it would be "2" if you're reading after both threads terminate, no?
uiop 2017-01-26 19:27:17
well, after both threads complete the put part of the operation
glguy 2017-01-26 19:29:16
osa1: The documentation is trying to explain that so long as you aren't using any extra putMVars that all code guarded by modifyMVar_ can only be executing on any one thread
glguy 2017-01-26 19:29:36
It's atomic in that no two threads will get the same value out of the mvar before another puts it back
osa1 2017-01-26 19:29:47
got it, thanks glguy
glguy 2017-01-26 19:29:53
similar to atomicModifyIORef, except that you can perform arbitrary IO in the critical section
dramforever 2017-01-26 19:40:00
Wait. You can't, right?
dramforever 2017-01-26 19:40:01
http://hackage.haskell.org/package/base-4.9.1.0/docs/Data-IORef.html#v:atomicModifyIORef
glguy 2017-01-26 19:41:24
The limitation of atomicModifyIORef, unlike modifyMVar_, is that atomicModifyIORef can't do the arbitrary IO
dramforever 2017-01-26 19:41:39
Oh, sorry I misread that
orzo 2017-01-26 19:41:50
when cabal reconfigures with the most recently used options, it should print the options