Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Because that's how you do inter thread communication in haskell.

https://hackage.haskell.org/package/base-4.10.0.0/docs/Contr...

>An MVar t is mutable location that is either empty or contains a value of type t.

>They can be used in multiple different ways:

>1. As synchronized mutable variables,



I did say they were rarely needed, if one does need interthread communication then yes an MVar or two will probably be used under the bonnet somewhere. Threads can however be used without MVars. Haskell offers many concurrency and parallel programming primitives.

Compare with C++ where every smartpointer holds mutable state (even if it points to a immutable value) and triggers a memory barrier whenever it is accessed.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: