Fraser Waters

My feedback

  1. 16 votes
    Vote
    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      You have left! (?) (thinking…)
      6 comments  ·  F# Language  ·  Flag idea as inappropriate…  ·  Admin →
      Fraser Waters commented  · 

      @radek, maybe semantics like

      a.?b
      ===
      if a = null then None else Some (a.b)

      And chained together so

      a.?b.?c
      ===
      if a = null then None else (if b = null then None else Some (a.b.c))

      Would allow easy matching as well:

      match a.?b with
      | Some b -> printf "a.b is %A" b
      | None -> printf "a is null"

    • 13 votes
      Vote
      Sign in
      Check!
      (thinking…)
      Reset
      or sign in with
      • facebook
      • google
        Password icon
        Signed in as (Sign out)
        You have left! (?) (thinking…)
        5 comments  ·  F# Language  ·  Flag idea as inappropriate…  ·  Admin →
        Fraser Waters commented  · 

        This matches the behavior of % in C# (and nearly every other language), it would also be a significant breaking change. But adding a new builtin function to do this would be a good idea.

      • 1 vote
        Vote
        Sign in
        Check!
        (thinking…)
        Reset
        or sign in with
        • facebook
        • google
          Password icon
          Signed in as (Sign out)
          You have left! (?) (thinking…)
          2 comments  ·  F# Language  ·  Flag idea as inappropriate…  ·  Admin →
        • 168 votes
          Vote
          Sign in
          Check!
          (thinking…)
          Reset
          or sign in with
          • facebook
          • google
            Password icon
            Signed in as (Sign out)
            You have left! (?) (thinking…)
            15 comments  ·  F# Language  ·  Flag idea as inappropriate…  ·  Admin →
            Fraser Waters commented  · 

            Functional properties is a pretty good way of putting it. The one part that Bryan didn't really cover well in this is that the lens is an instance of an object itself. So given his example of "lens <@ A.B.C @>" that would create a lense for field C of field B of type A. That lens object is a function that can either get that value from an instance of A, or set that value on an instance of A (returning a new A).

            eg something like:
            let l = lens <@ A.B.C @>
            let a = // create some A value
            let c = get l a // c is now the same as a.B.C
            let newC = // create some C value
            let newA = set l a newC // newA is now the same as { a with B = { a.B with C = newC } }

            Lenses themselves aren't massively complex, it's pretty much just:
            type Lense<a', b'> = { getter : a' -> b'; setter : a' -> b' -> a' }
            let get lense obj -> lense.getter obj
            let set lense obj value -> lense.setter obj value

            but with that you can then add composibility and other nice functional things on top. The awkard bit of lenses is constructing those getter/setter functions (more so the setter), but the construction of those functions is also trivial to the compiler.

            Fraser Waters supported this idea  · 
          • 59 votes
            Vote
            Sign in
            Check!
            (thinking…)
            Reset
            or sign in with
            • facebook
            • google
              Password icon
              Signed in as (Sign out)
              You have left! (?) (thinking…)
              8 comments  ·  F# Language  ·  Flag idea as inappropriate…  ·  Admin →
              Fraser Waters commented  · 

              "Also, it would be nice if there was a way to create an Option<T> type (where T is a struct) without boxing the struct." This is already the case. Option is a proper generic type, when T is a value type the jit will create new instances of Option so that the value stored does not need to be boxed (Same way List<T> doesn't box value types).

              "For maximum performance, is there a reason why options on reference types cannot be just syntactic sugar on `null`?" I figure generics throw a spanner in the works here, if you have a generic method that takes a generic option that has to be done with the proper option class to support being able to pass both structs and classes in (structs couldn't be passed in as null, and nullable<T> is a totally different type).

              It's probably possible to have an optimization pass that erases instances of Option<class> to just class and replaces matches/instance methods (e.g. opt.IsNone becomes (opt == null)). There's probably some corner cases where you can't erase every instance, and of course if changes your public API which you may or may not be wanted, but it sounds possible.

              You could probably do a similar pass with Option<struct> to Nullable<T>. Nullable is a value type so it could help with performance and GC pressure, but that probably has even more corner cases.

            • 30 votes
              Vote
              Sign in
              Check!
              (thinking…)
              Reset
              or sign in with
              • facebook
              • google
                Password icon
                Signed in as (Sign out)
                You have left! (?) (thinking…)
                5 comments  ·  F# Language  ·  Flag idea as inappropriate…  ·  Admin →

                Updating to planned to indicate this is approved in general terms. A detailed design and implementation would be needed.

                Implementations of approved language design can now be submitted as pull requests to the appropriate branch of http://github.com/Microsoft/visualfsharp. See http://fsharp.github.io/2014/06/18/fsharp-contributions.html for information on contributing to the F# language and core library.

                Don Syme, F# Language and Core Library Evolution

                Fraser Waters supported this idea  · 
              • 45 votes
                Vote
                Sign in
                Check!
                (thinking…)
                Reset
                or sign in with
                • facebook
                • google
                  Password icon
                  Signed in as (Sign out)
                  You have left! (?) (thinking…)
                  2 comments  ·  F# Language  ·  Flag idea as inappropriate…  ·  Admin →
                  Fraser Waters supported this idea  · 

                Feedback and Knowledge Base