Are monads expressions, or are there statements in Haskell?

I have an ontological question about monks in a Haskell; I stagger about whether language makes a distinction between expressions and expressions in general. For example, I feel that in most other languages, any statement with type signatures a -> SomeMonadProbs ()will be considered an expression. However, since haskell is purely functional, and functions are composed of expressions, I'm a little confused about what haskell will say about monads in terms of expressing them.

+4
source share
3 answers

Here are a few thoughts.

a >>= b is an application, like any other application, so from a syntactic point of view, Haskell clearly has no statements, only expressions.

(., , ) "" "" Haskell.

>>= , , a >>= b WHNF. "" "" IO .

"" . , foo a >> foo a let bar = foo a in bar >> bar, foo, IO .

, , , , . , C C. C , , C . . C- .

Haskell, , C : , , , C.

, , , , , .

, IO - , , , Haskell .

+6

Monad - . , , do:

example :: [(Int, Int)]
example = do
    x <- [1..3]
    y <- [4..6]
    return (x, y)

desugars :

[1..3] >>= \x ->
[4..6] >>= \y ->
return (x, y)

... (>>=) , :

concatMap (\x -> concatMap (\y -> [(x, y)]) [4..6]) [1..3]

, , , do, (>>=).

"" Haskell do, :

x <- [1..3]

, , :

[1..3] >>= \x -> ... {incomplete lambda}

, Haskell, do -, , .

+9

. "" "" - , "" - ( ) .

do notation ". , : pat <- exp`` and let decls`.

in most other languages, anything that has a type signature a -> SomeMonadProbs ()will be considered an expression

Haskell is different from most other languages. This is a kind (not for this the difference for this is obvious, but the union of expressions and expressions in one construction).

+5
source

All Articles