dramforever 2017-03-05 01:49:26
abhiroop: What things can be non-reentrant?
dramforever 2017-03-05 01:50:07
Well, writeTVar, you can think of those writes as batched all the way to completion
dramforever 2017-03-05 01:50:36
And the changes are applied only if non of the results of the reads changed
dramforever 2017-03-05 01:50:48
It's like a super CAS loop
abhiroop 2017-03-05 01:51:34
dramforever: yes I am aware of the working of STM transactions
abhiroop 2017-03-05 01:52:04
In fact I was going through the composable transactions paper by SPJ, Simon Marlow et al when I was wondering about reentrancy
abhiroop 2017-03-05 01:52:17
No where in the paper they discuss reentrancy
abhiroop 2017-03-05 01:52:33
"What things can be non-reentrant?" -> Well any pure function
dramforever 2017-03-05 01:52:38
?
abhiroop 2017-03-05 01:53:50
I just want to clarify my definition of reentrancy
dramforever 2017-03-05 01:53:55
abhiroop: Can you give an example of where this is a problem?
abhiroop 2017-03-05 01:54:24
When a concurrent object itself actively yields without being preempted by the scheduler
abhiroop 2017-03-05 01:54:51
and talks to another cncurrent object
dramforever 2017-03-05 01:55:16
Huh
abhiroop 2017-03-05 01:55:23
which reenter the control flow back to the original concurrent object
dramforever 2017-03-05 01:55:35
"concurrent object" -> like thread?
abhiroop 2017-03-05 01:55:37
So obj A -> obj B -> obj A
abhiroop 2017-03-05 01:55:55
Isn't that reentrancy
abhiroop 2017-03-05 01:56:07
A TVar
dramforever 2017-03-05 01:56:26
Data doesn't have control flow don't they
dramforever 2017-03-05 01:56:38
s/don't/does
dramforever 2017-03-05 01:56:50
Damn I can't English
abhiroop 2017-03-05 01:57:07
Yes you are right
dramforever 2017-03-05 01:57:09
abhiroop: What do you mean by reentering the control flow back to some piece of data?
abhiroop 2017-03-05 01:57:27
Actually let me try to reframe my thoughts
abhiroop 2017-03-05 01:57:37
As you were telling
abhiroop 2017-03-05 01:57:40
A thread
abhiroop 2017-03-05 01:57:47
yes the control flow of a thread
abhiroop 2017-03-05 01:58:00
So Thread 1 -> Thread 2 -> Thread 1
abhiroop 2017-03-05 01:58:10
Is that reentrancy?
dramforever 2017-03-05 01:58:16
Yes it is
dramforever 2017-03-05 01:58:20
it goes like this:
abhiroop 2017-03-05 01:58:21
Cool
dramforever 2017-03-05 01:58:30
We have a TVar holding 1
abhiroop 2017-03-05 01:58:47
so any form of communication between the threads where there is yielding of control
dramforever 2017-03-05 01:58:53
Thread1 reads it, gets 1, but before the STM action completes, we switch to Thread2
abhiroop 2017-03-05 01:58:57
How do I get that to work?
dramforever 2017-03-05 01:59:22
Oh wait, *without* being preempted
abhiroop 2017-03-05 01:59:30
"we switch to Thread2" -> you mean the scheduler
abhiroop 2017-03-05 01:59:52
Oh wait, *without* being preempted -> EXACTLY
dramforever 2017-03-05 02:00:00
abhiroop: You can't really do that in STM
dramforever 2017-03-05 02:00:08
You have to do that in IO
dramforever 2017-03-05 02:00:22
STM transactions are meant to be small and quick
abhiroop 2017-03-05 02:00:37
and so use https://hackage.haskell.org/package/base-4.9.1.0/docs/GHC-Conc.html#v:unsafeIOToSTM
abhiroop 2017-03-05 02:00:57
?
dramforever 2017-03-05 02:01:13
abhiroop: The third bullet point in that
dramforever 2017-03-05 02:01:17
That's the problem, I suppose
abhiroop 2017-03-05 02:01:52
Yes this "Invariants that you expect to be true throughout your program may not be true inside a transaction, due to the way transactions are implemented."
dramforever 2017-03-05 02:02:13
So it doesn't handle the thing you call reentrancy
dramforever 2017-03-05 02:02:19
(I would call it 'coroutine')
abhiroop 2017-03-05 02:02:22
I am very used to lock based concurrency and using Reentrant locks
abhiroop 2017-03-05 02:02:33
"(I would call it 'coroutine')" -> Yes
abhiroop 2017-03-05 02:02:41
Thanks dramforever
spatial 2017-03-05 02:03:09
putmutablearray = do { arr <- newArray (512,512) 0 ; storearray "value-table" arr } IO and IOArray Int Int Should I split into two ?
dramforever 2017-03-05 02:03:38
abhiroop: When I use STM I send messages between threads through stuff like TChan
zeawee 2017-03-05 02:03:47
C
dramforever 2017-03-05 02:03:47
Not 'tell the other thread to work' directly
abhiroop 2017-03-05 02:04:07
Oh..
abhiroop 2017-03-05 02:04:24
Well actually thats what I was getting at
abhiroop 2017-03-05 02:04:39
how do you solve for cases which involves reentrancy
spatial 2017-03-05 02:04:52
Anyone can suggest error fixes for my code http://pastebin.com/mQcJJ4f5 ?
dramforever 2017-03-05 02:05:12
abhiroop: That makes me wonder
dramforever 2017-03-05 02:05:19
Why are you using two threads?
abhiroop 2017-03-05 02:05:37
Well actually no I am not.
dramforever 2017-03-05 02:05:59
Then, huh?
abhiroop 2017-03-05 02:06:03
Like I said I was reading the paper Composable Transactions and wondering about handling reentrancy
abhiroop 2017-03-05 02:06:08
:)
dramforever 2017-03-05 02:06:16
Well
dramforever 2017-03-05 02:06:42
That's like reading a baking tutorial and asking 'What about the bacon'?
contiver_ 2017-03-05 02:06:46
is there a way to get a list of constructors from a data type? I'm aware that if constructors take a different amount of parameters, then the list wouldn't be homogeneous and it would usually not be possible. But in my case it's a bunch of unary constructors, so I thought maybe there is a work around.
dramforever 2017-03-05 02:06:50
'? -> ?'
abhiroop 2017-03-05 02:07:13
yeah true :)
contiver_ 2017-03-05 02:07:31
Tried with Data.Data and Data.Typeable, but dataTypeConstrs gives a list of [Constr], not what I'm looking for :/
abhiroop 2017-03-05 02:08:49
dramforever: But I guess its not very difficult to think about cases of reentrancy
abhiroop 2017-03-05 02:08:54
On the top of my mind
abhiroop 2017-03-05 02:09:13
some mutually recursive function operating in a multi threaded environment
contiver_ 2017-03-05 02:09:17
I need to list the constructors for an Arbitrary instance, and would prefer to avoid repeating them (to keep a single source of truth)
melancholiac 2017-03-05 02:15:21
why does ghc package is so big (1146.92 MiB)?
bjobjo 2017-03-05 02:20:22
quick and stupid question: does GHC only consider 8 spaces valid indentation? I can't seem to make my nested where's work with 4.
spatial 2017-03-05 02:22:25
IO ( IOArray Int Int) to IOArray Int Int Get newArray and store in Map Is that possible ?
Fendor 2017-03-05 02:23:44
bjobjo, if i'm right in memory, it doesn't matter as long the indentations match up with the other lines
Fendor 2017-03-05 02:23:50
so 4 should be fine, 2 should be fine
Fendor 2017-03-05 02:23:54
never tried 3
Fendor 2017-03-05 02:23:55
oder one
bjobjo 2017-03-05 02:24:21
that's weird, I believe my editor has been set up with soft tabs everywhere, but I'll have to check with vim or something
Fendor 2017-03-05 02:25:11
do manual spaces, then youll see whats the problem
bjobjo 2017-03-05 02:25:49
looks all right in vim too, all spaces everywhere (I've had troubles with mixed tabs/spaces before)
contiver_ 2017-03-05 02:26:22
bjobjo, if you can show us the code, we might be able to find out why.
bjobjo 2017-03-05 02:26:39
one sec
lpaste_ 2017-03-05 02:28:05
bjobjo pasted "nested where indentation issues" at http://lpaste.net/353233
contiver_ 2017-03-05 02:28:57
bjobjo, if I'm not mistaken, you need to indent the 2nd where past the 1st one
bjobjo 2017-03-05 02:29:14
oh, so since where is 5 chars, 4 spaces is not enough?
Tuplanolla 2017-03-05 02:29:39
This also applies to statement-let, bjobjo.
contiver_ 2017-03-05 02:30:42
bjobjo, my understanding is that the column for the first where's definitions starts where mapOperatingSystem starts
hexagoxel 2017-03-05 02:30:55
bjobjo: the "mapOS .." defines the indentation level for the where-decls. But the second where goes left of that.
contiver_ 2017-03-05 02:31:00
not sure if it would work just below it, but probably a single space after it, works.
hexagoxel 2017-03-05 02:31:14
^
hexagoxel 2017-03-05 02:32:03
you can decrease overall indentation by newline after first where.
contiver_ 2017-03-05 02:32:34
also, you can avoid the second where. Just define both functions under the first one, it should also work, and is cleaner (IMO).
bjobjo 2017-03-05 02:33:02
all right, let me try it out a bit
bjobjo 2017-03-05 02:33:05
thanks all :)
lpaste_ 2017-03-05 02:33:58
hexagoxel annotated "nested where indentation issues" with "nested where indentation issues (annotation)" at http://lpaste.net/353233#a353234
bjobjo 2017-03-05 02:34:49
in this particular case, skipping the second where certainly looks better