Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm referring to "information hiding" by providing a function that uses currying in order to close over data that cannot be accessed from the caller. For example:

    (* foo.ml *)
    let bar =
      let foo = lambda x . lambda y .
        if y == 0 then { getFoo : lambda z . 0 }
        else { getFoo : lambda z . (x * z - x + z) / y }
        end
      in foo 3

    (* bar.ml *)

    include foo.ml

    let y = bar 5
    bar.getFoo(4)
It sure seems to me that bar is hiding the 3 from bar.ml (and there are much more complicated examples where foo.ml really can't get at the captured type, for instance), and at the same time it's capturing the value of 5. The function getFoo on bar is bound to it (the record type can desugar to more curried lambdas, if necessary, it's just tedious and this illustrates my point better).

None of this seems to have anything to do with mutation, to me, though it certainly seems to have both information hiding and binding logic and data. The fact that it can be compiled not to use closures (using whole-program compilation) is immaterial; the same is true for the same program specified with objects in mutable languages (SML has both mutation and closures, and MLton does exactly that).



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: