Why does a partial application have value restriction?

后端 未结 4 1902
日久生厌
日久生厌 2021-01-24 02:15

I can understand that allowing mutable is the reason for value restriction and weakly polymorphism. Basically a mutable ref inside a function may change the type in

4条回答
  •  不思量自难忘°
    2021-01-24 02:33

    Partial application doesn't preclude mutation. For example, here is a refactored version of your code that would also be incorrect without value restriction:

    let aux cache x =
        match !cache with
        | Some y -> y
        | None -> cache := Some x; x
    
    let remember = aux (ref None)
    

提交回复
热议问题