user-pic

Philed

  • Commented on Writing State Monads in Ocaml
    Ack. Of course. “Initial state” is a better term. So here’s a question: what happens when we want to allow the state to be uninitialised? In most languages, the answer is obvious: we just set the variable to null. But,...
  • Commented on Writing State Monads in Ocaml
    In Haskell, it’s just a parameter to “runState”. I think what you’re trying to do is avoid the need for this parameter and just have a default value. But I think in that case you want to use option, and...
  • Commented on Writing State Monads in Ocaml
    Hey Chris. I think this is a great way to learn monads. There’s probably a fancy way to explain the implementation of “get” and “put”. Maybe it’d help to write “modify”. The purpose of modify is to mutate the state...
Subscribe to feed Recent Actions from Philed

  • cyocum commented on Writing State Monads in Ocaml

    Hi Phil,

    Thanks for this! I am still unsure about the empty. How do I fire the function in that case without something of the proper time to pass in?

  • cyocum commented on Writing State Monads in Ocaml

    So I think I have figured it out. Basically what I am calling “empty” is what Haskell calls “initial state”. I force the user of StateMonad to know what the inital state is when they define the module. I am OK with this. I will just rename the value to reflect this.

    I am still interested in the option route as well though. I tried to implemented but the type checker went a bit crazy so I will need to think about it more before I try it again.

    Thanks!

Subscribe to feed Responses to Comments from Philed

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.