kosmikus,
@kosmikus@functional.cafe avatar

Later today, 2024-05-15, at 1830 UTC, join Edsko and me for the 25th episode of the #Haskell #Unfolder "from #Java to Haskell" live on #youtube.

https://well-typed.com/blog/2024/05/haskell-unfolder-episode-25-from-java-to-haskell/

maralorn,
@maralorn@chaos.social avatar

@kosmikus I was wondering, why using an MVar? The possibility for it to be empty seemed completely unnecessary for the example.

mangoiv,
@mangoiv@functional.cafe avatar

@maralorn @kosmikus im pretty sure that was to replicate the behaviour of the Java version, no? Edsko did talk about examining the size of the critical region being the original motivation behind the Java code.

Using an MVar is using a lock. while the MVar is taken, no other Thread can take it.

maralorn,
@maralorn@chaos.social avatar

@mangoiv @kosmikus Using a var type which takes a lock makes sense. But MVar seems a bit unfiting, because it can be empty. I was wondering what the argument over atomicModifyIORef or using a TVar would be. It seems like MVar has the best ergonomics and concurrency behavior?

I always wonder why the square of

TMVar TVar
MVar ?

seems to be missing a corner.

mangoiv,
@mangoiv@functional.cafe avatar

@maralorn atomicModifyIORef doesn’t seem to work very well here in particular, mind that we throw an exception in one of the branches. Tbh I think an MVar is the perfect fit here 😅

maralorn,
@maralorn@chaos.social avatar

@mangoiv In my mind an MVar a is similar to an IORef (Maybe a) and that doesn’t feel quite right.

mangoiv,
@mangoiv@functional.cafe avatar

@maralorn oh, in my mind its a lock which also has a value, locking the MVar is taking it, unlocking it is putting it. Or, if you so wish, you can even do it in reverse.

As far as i understand what you normally call a lock is what we’d call an MVar ().

kosmikus,
@kosmikus@functional.cafe avatar

@mangoiv @maralorn Yes, I agree with this view. I don't think Maybe is the right analogy. The MVar being empty is not a case you have to explicitly deal with, it already has a behaviour attached to it (blocking). Regarding the missing entry in the square, isn't that just an IORef?

maralorn,
@maralorn@chaos.social avatar

@kosmikus

@mangoiv

Yeah, It's kinda IORef but I thought that doesn't count because it has less concurrency guarantees.

But I think I get now why MVars are much more useful. I have even used TMVars myself as locks when the action I wanted to do with it contained effects.

mangoiv,
@mangoiv@functional.cafe avatar

@kosmikus awesome! We need more videos like this. I really liked it when Rae did it a few years ago, however, I think it had some issues wrt recognising that you do things differently in the different ecosystems.

kosmikus,
@kosmikus@functional.cafe avatar

@mangoiv I'm embarrassed to admit I might not have watched this one. Well, you can tell me later whether we are running into the same issues or manage to avoid them somehow, and why.

mangoiv,
@mangoiv@functional.cafe avatar

@kosmikus 🙂‍↕️ will do

https://m.youtube.com/watch?v=bPyR1ttdE7o <- this is the video

mangoiv,
@mangoiv@functional.cafe avatar

I liked it! Much more serious example and much more Haskell-looking translation.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • haskell
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines