Вопрос

In a Haskell tutorial I ran across the following code:

do [...]
  let atom = [first] ++ rest
  return $ case atom of

Note that the let expression does not have an in block. What is the scope of such a let expression? The next line?

Это было полезно?

Решение

Simply put, it's scoped "from where it's written until the end of the do".

Note that within a do statement, let is handled differently.

According to http://www.haskell.org/haskellwiki/Monads_as_computation#Do_notation , it is interpreted as follows:

do { let <decls> ; <stmts> }
  = let <decls> in do { <stmts> }

Другие советы

The scope is the rest of the do block.

See §3.14 of the Haskell Report (specifically, the fourth case in the translation block). (Yes, this is the section about do blocks, because let without in is only valid inside a do block, as Porges points out.)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top