1

Topic: Monads

I begin a subject and I invite in it those who is better than me in it understands For which practical needs monads are suitable? Also what is called as a monad in the languages which are distinct from Haskelja? Somehow more or less clearly that is is specific in lazy eval Haskele there is no possibility to guarantee the execution order, differently than through f (g (x)) And somehow more or less clearly that was specific monad IO and is made that after deployment bind to receive f (g (x)) with an order warranty that is obviously necessary to input-output. More or less clearly that such Maybe and what for it. More or less clearly that on monads it is possible to make  from JS, for this purpose bind in certain cases should not call the lambda, and push it in new object, whence it will be called once then. Somehow so. Not so clearly, what this mechanism suits. I will try to express the understanding that such a monad in Haskele generally: - Monad T there is a wrapper round value T - thus a wrapper dynamic, i.e. "interior" can and always not lie in storage, and can be under construction at reversal->> =, he bind, derives an interior from a monad and gives it there (to that lambda) where asked. I.e. "tears". - thus  the lambda is obliged to return "a wrapped up" monad. For this purpose is return which on an interior builds a monad (in the elementary case puts it in a new monad). I.e." Turns ". - at a spelling  and resets for the monads it is necessary to observe identities of a type" to Turn (to Tear (M)) = M ". The old kind set dresser which turns out it is possible to implement in normal  languages inheritance with overlapping . The only thing: thus objects will be" under the link ", and the monad allows" on value ". I am right? And in other languages as? Thus there is still such artful trick: the list is a monad, and bind at it - iteration under the list. It somehow looks a little for no reason at all.

2

Re: Monads

3

Re: Monads

MSS> it is not so clear, what this mechanism suits. Life (and a strong team) forced to write in severe  style on scala. Month I write, two I write, already even got used. But every day it would be desirable to shout bullshit because , and  the salt of monads is not enough monads in general - that you work dataful known (or the unknown person) type, without knowing that in what they was specific to a wrapper. For example monad Id (in scala, I do not know as at others is called) are simply data, a wrapper without a wrapper and on idea should be thrown out completely at a compilation stage. Monad Option - about that that the data or is or they are not present. And monad Task - allows to apply the same algorithm to asynchronously  to the data. The algorithm if it it is real under monads is made, should not assume anything about that in what wrapper at all the data come. It works immediately dataful and simply knows that they will be in any wrapper. The most simple example - at you is function of addition Int wrapped in any monads. If this operation to apply to monad Id - you will receive addition of values. If to List that addition of lists. If to Task the data for addition will undertake whence asynchronously, etc. In an ideal this mechanism allows to do well very generalized algorithms. For example - you made the difficult mechanism of handling of any big data. If you implement it is admissible in C# - you can select one or the other - or to make API asynchronous for support of asynchronous calls. Or synchronous. (The variant when synchronous API simply wrapper over asynchronous calls while is thrown out). On monads - depending on type of a monad at the user of yours  after compilation it turns out or purely asynchronous code (if it applied Task), or purely synchronous (in an ideal without any overhead projector on wrappers if it took the data from an array and feeds them to you through an Id-monad). Or the user can not only receive data handling, but also save any information imperceptibly for processing (monad State). In a reality (well at least in scala, I I do not know as in haskell) - an overhead projector on these wrappers in places hellish - because of that that many lambdas, many objects form and deleted on each operation, it is etc. finite here any exclaims "yes I on OOP too most can" (I shouted), but is not present. It turns out not absolutely too most, with monads of possibilities it is a bit more. But while the price for these possibilities () outweighs and is strong, a profit from their usage. I can certainly in a year of daily usage of monads I will think differently. That it is pleasant to me in these monads so this that that very beautifully dares the task of data handling with saving of that context whence the data came, and the context and its existence are invisible to the processing. And generally saving (and concealment) any contexts. Here you have for example an algorithm of adding of money for the account of the user on any condition. And if all competently to push in monads the algorithm of concept will not have about the user (i.e. literally, on an input to it of copy User any there will not come), about that whence it is the user undertook, anything superfluous. And if you decide to add to the user multiple currency purses - you have a variant  the existing code without changing it at all, simply given will come enveloped in a monad which knows about a specific purse. And the code which enlists - remains to the same. There is a dream to try to express this  magic somehow syntactically (most likely in Nemerle/Nitra where still). Because that hell of typification round monads which I everywhere saw, flies up only at most  .

4

Re: Monads

Hello, hi_octane, you wrote: _> in general the salt of monads - that you work dataful known (or the unknown person) type, without knowing that in what they was specific to a wrapper. Never this subject studied, but always it seemed that monads are necessary for IO or  with an external world, i.e. there where the state (operation is necessary. As it is known in  states are not present, for angrily, but somehow to interact with an external world it is necessary, here and invented any mechanism. Or monads something  or absolutely another?

5

Re: Monads

6

Re: Monads

Hello, Sharov, you wrote: S> Or monads something  or absolutely another? Much bigger. This general property of many calculations. Where details are not considered, and the most important thing undertakes: (1) ability to create new calculation on a primitive (a.k.a to "pure" value) and (2) possibility to continue old calculation by means of new to which "the result" received during the first calculation and then combined calculation turns out is transferred as though. It is all does such calculations composite. They become building units from which it is possible to create new calculations. For example, a monad it is possible to describe activity of the discrete process in discrete-sobytijnom modeling, and "arrow" then (the bound concept) - some variant of units (cards) from modeling language GPSS. With reference to the programming, one of surprising applications of monads is possibility gracefully to write down asynchronous calculations and also gracefully to work with so-called "transactional storage" (Software Transactional Memory) for multithreading taming where here is how time difficult things form, combining among themselves the simple. Therefore it is actually very rare, when  or  it is possible to force to write in any other programming language But I understand that without practice it is all to understand difficult, and it is impossible. I when faced it on the first understood nothing from those descriptions the general words that saw. At once I will note that the compiler  broadcasts monads very effectively, as far as possible, often removing all additional layer of abstractions which here arises. Actually, therefore on calculation in monad IO almost same code, as well as the normal code there on With or a C ++ is generated.

7

Re: Monads

Hello, hi_octane, you wrote: Thanks. This best explanation of monads human language of that I saw.

8

Re: Monads

Hello, Maxim S. Shatskih, you wrote: MSS> For which practical needs monads are suitable? My favourite example - parser-kombinatory. And so, good nontrivial application of monads is difficult for meeting. In Haskele on them express effects - exceptions, , input-output,  a state and their various combinations. I.e. that in other languages already and so is normally. MSS> also what is called as a monad in the languages which are distinct from Haskelja? There are languages similar to Haskel, like Idrisa, there monads same. And in more other languages monads normally or generally name nothing (and to express a monad explicitly in the majority of languages it is impossible), or conditionally call monads the same  and , and it is not always correct. About 8-10 years ago on monads was big , each adherent  should write the explanation of monads and specify that implicitly monads in other languages are (but muzhiks did not know), and explicitly a horse-radish will express humanly. Only on Haskele yes on the Rock. And now, like,  quieted down. Who writes on , automatically them uses, they there everywhere in standard library and without them there it is difficult. Who on the Rock and around noted that in many cases it is enough  functors, instead of monads. To write beautiful  the code which would work in unknown monads different a priori, it is necessary, at first, that the type system allowed to abstract not only from type , but also from the container (functor) F <T>, i.e. are necessary higher-kinded types. And they except  with a rock anywhere are not present practically, even in  are not present. And secondly syntax support, the same do-notation is necessary, it too anywhere especially is not present. So monads somehow did not go to other languages.

9

Re: Monads

Hello, dsorokin, you wrote: D> With reference to the programming, one of surprising applications of monads is possibility gracefully to write down asynchronous calculations and also gracefully to work with so-called "transactional storage" (Software Transactional Memory) for multithreading taming where here is how time difficult things form, combining among themselves the simple. Therefore it is actually very rare, when  or  it is possible to force to write in any other programming language And it is possible more in detail?

10

Re: Monads

DM> to write beautiful  the code which would work in unknown monads different a priori, it is necessary, at first, that the type system allowed to abstract not only from type , but also from the container (functor) F <T>, i.e. are necessary higher-kinded types. And they except  with a rock anywhere are not present practically, even in  are not present. And secondly syntax support, the same do-notation is necessary, it too anywhere especially is not present. So monads somehow did not go to other languages. Here that in a rock enrages (and probably in  though I on it and do not write, but  sometimes I read) - so this that that this do-notation is necessary in an explicit form. And in a rock - so it  in for-comprehension which stumbles on the elementary things (type normally  in this  to put). Really it is impossible to add sugar in the compiler that he recognized the code on monads, and is correct it  without the do-notation? Like the task it is not more difficult than that which solves the compiler C#  function with async/await.

11

Re: Monads

Hello, hi_octane, you wrote: MSS>> it is not so clear, what this mechanism suits. _> life (and a strong team) forced to write in severe  style on scala. Month I write, two I write, already even got used. But every day it would be desirable to shout bullshit because monads , and  poorly What IDE use? To me very much hinders IDEA since she often badly recognizes  the code, highlighting red correct expressions and without highlighting the incorrect. cats or scalaz? Know any severely-monadnyj  the project on a rock? This subject is deeply interesting to me, but in it many theorists offering impractical decisions were dug round. And anybody from them cannot show the code.

12

Re: Monads

scf> What IDE use? To me very much hinders IDEA since she often badly recognizes  the code, highlighting red correct expressions and without highlighting the incorrect. IDEA like is not responsible for illumination scala. The compiler of a rock answers scala plugin, which on sensations in a basis. Accordingly if the code is so severe, the bad coloring will be everywhere. The standard only on source codes, on places use who that wants - here is and  with IDEA, and basic  with the console (probably vim, but any very color for vim'a), and someone with something similar on Far. scf> cats or scalaz? Know any severely-monadnyj  the project on a rock? Alas, in a rock-projects while the terrible lamer so to advise to me still very much early. But all that office where I got does, it does in the uttermost open-sors, and it would be desirable to trust that there the suitable Same code cats is used permanently. https://github.com/rchain/rchain/children in under-project rholang, well and mtl / tagless-final in node and communication especially powerfully shutter. There the reference example is direct as "effects" for decomposition of the network code to a state when in tests the network code is tested are used, and thus no connections with a network are present and in . scf> this subject is deeply interesting to me, but in it many theorists offering impractical decisions were dug round. And anybody from them cannot show the code. If interest-interest is direct is - I can adjust contact for communication,  and will begin itself . For the next month the person 5 want to gather additionally. Pure , not a Herbalife.

13

Re: Monads

Hello, Sharov, you wrote: S> Hello, dsorokin, you wrote: D>> With reference to the programming, one of surprising applications of monads is possibility gracefully to write down asynchronous calculations and also gracefully to work with so-called "transactional storage" (Software Transactional Memory) for multithreading taming where here is how time difficult things form, combining among themselves the simple. Therefore it is actually very rare, when  or  it is possible to force to write in any other programming language S> And it is possible more in detail? https://www.amazon.com/Parallel-Concurr … 1449335942 I at myself use STM, but is faster instead of automated wait/notify. By the way, one of variants of usage for Haskell.

14

Re: Monads

Hello, D. Mon, you wrote: DM> to write beautiful  the code which would work in unknown monads different a priori, it is necessary, at first, that the type system allowed to abstract not only from type , but also from the container (functor) F <T>, i.e. are necessary higher-kinded types. And they except  with a rock anywhere are not present practically, even in  are not present. And secondly syntax support, the same do-notation is necessary, it too anywhere especially is not present. So monads somehow did not go to other languages. In Rust receptions are the different. For monads it is convenient to define not F <T> and trait F {type T;}. And if to use FnOnce then all will be got. Even monad Cont can be represented, of what it was impossible even to dream on a C ++.

15

Re: Monads

Hello, hi_octane, you wrote: scf>> this subject is deeply interesting To me, but in it many theorists offering impractical decisions were dug round. And anybody from them cannot show the code. _> if interest-interest is direct is - I can adjust contact for communication,  and will begin itself . For the next month the person 5 want to gather additionally. Pure , not a Herbalife. Certainly it is interesting, threw off in a LAN.

16

Re: Monads

scf> Certainly it is interesting, threw off in a LAN. And me somehow already asked, the link remained on a site the Author: hi_octane Date: 12.03 20:12.

17

Re: Monads

Hello, hi_octane, you wrote: _> Here that in a rock enrages (and probably in  though I on it and do not write, but  sometimes I read) - so this that that this do-notation is necessary in an explicit form. And in a rock - so it  in for-comprehension which stumbles on the elementary things (type normally  in this  to put). And what not so in for-comprehension? Like all as in  there with if th: import cats.effect. IO val printJohn = IO {println ("John!")} val printSusan = IO {println ("Susan!")} val getName = IO {"Susan"} val program: IO [Unit] = for {name <- getName _ <- if (name == "John") printJohn else printSusan} yield {}

18

Re: Monads

N> And what not so in for-comprehension? Like all as in  there with if th. Well from my belltower it is an artificial construction which looks as a crutch, walks as a crutch and grunts as a crutch. N> N> _ <- if (name == "John") printJohn else printSusan N> and the same variant, but instead of printJohn it is necessary the whole pack of actions, and instead of printSusan another? I how many councils did not ask - gurus speak carry out in local function and in it the for. Also it is a crutch because should not impose language a code composition, moreover such. In C# this problem solved hardly more naturally in async/await, but alas in CLR is not present higher-order types so there are no also monads.

19

Re: Monads

Hello, hi_octane, you wrote: _> Also it is a crutch because should not impose language a code composition, moreover such. In C# this problem solved hardly more naturally in async/await, but alas in CLR is not present higher-order types so there are no also monads. http://monadless.io/? Itself did not use and I do not want, as breaks RT, but it is subjective: https://www.reddit.com/r/scala/comments … mposition/

20

Re: Monads

N> http://monadless.io/? Thanks, did not know about the such. I will try (let even in the project do not allow to drag, so though for myself), under the total . It will be healthy if pulls all that I permanently use.

21

Re: Monads

22

Re: Monads

Hello, D. Mon, you wrote: DM> to write beautiful  the code which would work in unknown monads different a priori, it is necessary, at first, that the type system allowed to abstract not only from type , but also from the container (the functor) F <T>, i.e. are necessary higher-kinded types. And they except  with a rock anywhere are not present practically, even in  are not present. Is in a C ++, you know DM> And secondly syntax support, the same do-notation is necessary, it too anywhere especially is not present. So monads somehow did not go to other languages. The Author is if needed implemented through macroes in a C ++: Evgeny. Panasyuk Date: 07.01.14.

23

Re: Monads

Hello, hi_octane, you wrote: _> Here that in a rock enrages (and probably in  though I on it and do not write, but  sometimes I read) - so this that that this do-notation is necessary in an explicit form. And in a rock - so it  in for-comprehension which stumbles on the elementary things (type normally  in this  to put). Really it is impossible to add sugar in the compiler that he recognized the code on monads, and is correct it  without the do-notation? Like the task it is not more difficult than that which solves the compiler C#  function with async/await. Alternative of the DO-notation (that is alternative of cutting of the code on closings, let and automatic) is call-with-current-continuation - the runtime environment in an explicit form gives to all of us necessary for repeated continuation from a current place. It for example allows  the code without changing customary syntax. Here a specific example the Author: Evgeny. Panasyuk Date: 16.01.14.

24

Re: Monads

Hello, hi_octane, you wrote: _> In C# this problem solved hardly more naturally in async/await, but alas in CLR is not present higher-order types so there are no also monads. Even if would be - await it all the same not that, for example monad List on it not to express, as support of repeated start of continuation from one place is necessary.

25

Re: Monads

Hello, Evgeny. Panasyuk, you wrote: DM>> to write beautiful  the code which would work in unknown monads different a priori, it is necessary, at first, that the type system allowed to abstract not only from type , but also from the container (functor) F <T>, i.e. are necessary higher-kinded types. And they except  with a rock anywhere are not present practically, even in  are not present. EP> Is in a C ++, you know Yes, a C ++ and D too. DM>> And secondly syntax support, the same do-notation is necessary, it too anywhere especially is not present. So monads somehow did not go to other languages. EP> the Author is if needed implemented through macroes in a C ++: Evgeny. Panasyuk Date: 07.01.14. Oh, it is horror. As exercise still descends, but in practice by it it is impossible to use.