Does Haskell optimizer utilize memoization for repeated function calls in a scope?

后端 未结 3 1855
醉梦人生
醉梦人生 2021-01-17 12:04

Consider this function:

f as = if length as > 100 then length as else 100

Since the function is pure it\'s obvious that the length will

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-17 12:19

    The case you are describing has more to do with common subexpression elimination than memoization, however it seems that GHC currently doesn't do that either because unintended sharing might lead to space leaks.

提交回复
热议问题