문제

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