How are Dynamic Programming algorithms implemented in idiomatic Haskell?

前端 未结 5 1378
执念已碎
执念已碎 2020-12-07 14:22

Haskell and other functional programming languages are built around the premise of not maintaining state. I\'m still new to how functional programming works and concepts in

5条回答
  •  一向
    一向 (楼主)
    2020-12-07 14:40

    Dynamic programming algorithms usually exploit the idea of reducing a problem to simpler problem(s). Its problems can be formulated as some basic fact (say, the shortest path from a square cell to itself has length 0) plus a set of recurrent rules which show exactly how to reduce problem "find shortest path from cell (i,j) to (0,0)" to problem "find shortest paths from cells (i-1,j), (i,j-1) to (0,0); select the best". AFAIK this can be easily expressed in functional style program; no state involved.

提交回复
热议问题