What exactly means effective

From time to time I read the term “effect,” but I still cannot give a clear definition of what this means. I assume that the right context is efficient calculations, but I also saw the term spectacular meaning )

I used to think that effective remedies have side effects. But in Haskell there are no side effects (except to some extent IO). There is still efficient computing everywhere.

Then I read that monads are used to create efficient calculations. I can somewhat understand this in the context of the Monad State. But I do not see a side effect in the monad Maybe. All in all, it seems to me that Monads that wrap a functionally similar thing are easier to see as producing side effects than Monads that just wrap a value.

When it comes to functors Applicative, I get even more lost. I have always seen applicative functors as a way of mapfunction with several arguments. Here I do not see a side effect. Or is there a difference between effects and effects?

+14
source share
3 answers

A ( ). Haskell . IO: IO, , , , IO, main.

, , , "", "". , f kind * -> *, f a a - "" - "" .

, ( ), . . , Maybe "" , ( ), [] "" , ( ) . .

"" "" . Functor, Applicative Monad , (Functor , Applicative Monad ). Monad s , , "" ,

(>>=) :: m a -> (a -> m b) -> m b

: a, , " , , - ".

+13

, " " - , . , , .

:

let
  y = foo x
  z = bar y
in foobar z

foo, bar, foobar . , ? :

do
  y <- foo x
  z <- bar y
  foobar z

, (>>=) . , - , , .

  • , . , . .

  • Maybe -something, , () bar Nothing, . . (I.e., , foobar.) , , . . .

  • --, . , . .

  • , () foo foobar, , , bar. , , .

  • IO . ( ), ( -).

  • ST IO. , .

  • STM , , ... , .

  • ! , ...

+3

, "" .

" " " " , :

Applicative - , Monad , , .

"" "" ; , . , Applicative (. 3):

f, , [...] Applicative:

[ Haskell Applicative]

S K [. S K, Reader/function Applicative] .

, :

  • - , Applicative ".

  • , Applicative.

  • Monad .

, "", , Wadler . , 6 Monads :

a → b a → M b. , a b, , M. , , , .

, . 21:

, ? , , , , - . [a], , . a → b a → [b].

" ", . :

, , , , .

, , " " , .. " [ ] ( )". "", , , " ", , , Monad. , , Applicative, .

, "" :

  • "" "": ;

  • "" "": .

, "". , , Functor, , Applicative Monad ( , , : , ?).

+3

Source: https://habr.com/ru/post/1694919/


All Articles