Why is foldl defined in a strange way in Racket?

前端 未结 4 2023
遇见更好的自我
遇见更好的自我 2020-12-03 00:25

In Haskell, like in many other functional languages, the function foldl is defined such that, for example, foldl (-) 0 [1,2,3,4] = -10.

Thi

4条回答
  •  無奈伤痛
    2020-12-03 01:23

    Racket's foldl and foldr (and also SRFI-1's fold and fold-right) have the property that

    (foldr cons null lst) = lst
    (foldl cons null lst) = (reverse lst)
    

    I speculate the argument order was chosen for that reason.

提交回复
热议问题