Does Haskell have a fully applied braking function in curry?

Or else:

Can I apply all arguments to a shadow function without evaluating it ? So, would I still have the value of the function, and not the result of the calculation?

Example:

add x y = x + y
add1 = add 3   {- add1 is a function -}
add2 = add1 4  {- add2 is 7, but I would like to have a function 
                  I can call with no arguments!? -}

The reason is the transfer of functions that are completely connected and can be called in arbitrary situations and without the need to provide additional arguments.

No tricks (e.g. providing a fictitious last argument, such as 1 or True on the call site).

+4
source share
1 answer

. , , . , , Haskell , System FC, . , 7 Num a => a, , Haskell , System FC , Num a a. , , .

, , , , ! , , ,

x = really expensive computation

x. x ( seq evaluate ..), x, .

:

, GHCi , add1 4 7, ?!

! add1 4 GHCi. GHCi , , print. print , , ! , GHCi :print :sprint, .

Prelude> let foo = (1+2, 3+4) :: (Int, Int)
Prelude> :print foo
foo = ((_t3::Int),(_t4::Int))
Prelude> fst foo
3
Prelude> :print foo
foo = (3,(_t5::Int))
Prelude> snd foo
7
Prelude> :print foo
foo = (3,7)

: . GHC , , , . " ", " ".

+10

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


All Articles