Skip to content

Space leak due to memoize ? #24

@phlegmaticprogrammer

Description

@phlegmaticprogrammer

Check if the space leak that is avoided in the following code fragment by making "f" part of "'a comp" happens in some form also in the Babel-17 implementation of memoize .

datatype 'a comp = NotComputed of (unit -> 'a) | Computed of 'a | Exception of exn

fun memo f = 
let 
  val result  = ref (NotComputed f)
  fun g () = 
    case !result of 
      NotComputed f => 
        let val r = f() in
          result := Computed r;
          r
        end handle e =>
          (result := Exception e; raise e) 
    | Computed r => r
    | Exception e => raise e
in
  g 
end 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions