Why do you need to use a keyword in a block?

What is the reason for having a block letin do.

-- codeblock A
main = do
  let a = 0
  let f a = a + 1
  let b = f 0
  print (a,b)

-- codeblock B
main = do
  a = 0
  f a = a + 1
  b = f 0
  print (a,b)

Suppose all letwithout inmust be followed =(is that true?)

The compiler should be able to point letfrom =and preprocess / de-sugar codeblock Btocodeblock A

using letin this case seems unnecessary, for example, you can write codeblock C, but select a recordcodeblock D

-- codeblock C
main = do
  print (a,b)

a = 0
f a = a + 1
b = f 0

-- codeblock D
main = do
  print (a,b)

function  a = 0
function  f a = a + 1
function  b = f 0

To clarify, my assumption does not include let, which follows in, which should remain untouched.

-- codeblock E
main = do
  a = 0
  f a = a + 1
  b = f 0
  c = let d = 1 
          e = 1
      in d + e
  print (a,b,c)
+4
source share
2 answers

, , , : , .

, , , :

foo :: [Int]
foo = do
  x <- return [1]
  y = 0:x
  x = [1..5]
  y

:

foo1 :: [Int]
foo1 = do
  x <- return [1]
  let y = 0:x
  let x = [1..5]
  y

foo2 :: [Int]
foo2 = do
  x <- return [1]
  let y = 0:x
      x = [1..5]
  y

foo1 [0,1] foo2 [0,1,2,3,4,5]. , , , let , , , .

chi, - , , let: , .

+14

let , do, , (, - lens).

do
  p1.x += delta             -- (+=) is a custom operator
  p2.y -= delta             -- (-=) is a custom operator
  let delta' = delta*delta
  p3 .= Point delta' delta' -- (.=) is a custom operator

delta' - let.

+4

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


All Articles