Cannot create apply function with static language?

前端 未结 12 895
梦谈多话
梦谈多话 2021-02-04 02:09

I have read that with a statically typed language like Scala or Haskell there is no way to create or provide a Lisp apply function:

(apply #\'+ (lis         


        
12条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 02:37

    try folds. they're probably similar to what you want. just write a special case of it.

    haskell: foldr1 (+) [0..3] => 6

    incidentally, foldr1 is functionally equivalent to foldr with the accumulator initialized as the element of the list.

    there are all sorts of folds. they all technically do the same thing, though in different ways, and might do their arguments in different orders. foldr is just one of the simpler ones.

提交回复
热议问题