Abel

My feedback

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

      Your title "turning properties into functions" suggests that F# wouldn't have support for this, but you can already do that (get the function accessor of the property):

      let x = classWithNameProperty()
      let f = x.get_Name // x.Name property as a function, f: unit -> string

      But without the syntax decorations proposed in the comments, I don't see how this can be turned into a function if the object is not known (which is the second part of your request).

      Unless you need this for many different properties, you can create your own object-less syntax using ducktyping, but this is "per property":

      type MyTest() =
          member __.Name = "foo"

      let inline name (x: ^a) = (^a: (member Name: string) x)

      let f() =
          Seq.singleton (MyTest())
          |>Seq.map name                // works on any object in the seq with x.Name property

      Of course, it would be much nicer to have standard syntax for this.

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

          I believe I have seen this request before. The problem is that "inline" changes the behavior and is often inevitable to create semi-polymorphic (duck-typed) functions and types. Consider:

          let f a b = a + b // a and b are ints
          let inline f a b = a + b // a and b requires member (+)

          Or:

          let f a b = int a * int b // a and b are ints
          let inline f a b = int a * int b // a and b require op_Explicit

          If you call this code:

          let result = f 1.23 4uy // the first will work with both, inferred float -> byte -> int
          let result = f 1.23 4L // works with "inline", does not compile without (wrong type)

          If your only requirement is to remove optimization of "inline" and the different inference rules have no effect, it would make (some) sense to disallow it, esp. since during debugging it is beneficial to be able to step through the method.

          You can simplify your above code somewhat:

          let
              #if DEBUG
              inline
              #endif
              writeBoundedSequence ....

          Though I would suggest you create a new compiler constant, say INLINE:

          let
              #if INLINE
              inline
              #endif
              writeBoundedSequence ....

          That is because you would want to be able to see debug behavior of the inlined version and this way you can better control when and where INLINE is used.

        • 27 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 →
            Abel commented  · 

            You can already do generalization:

            type Test =
                | Foo of string
                | Bar of string

            static member getString x =
                match x with
                | Foo s
                | Bar s -> s // both conditions wrapped in a single continuation

            It would, however, be nice if this is generalized further into something like:

            static member getString x =
                match x with
                | _ s -> s

            But that doesn't work well with tuples as in your original example. You'd still have to iterate them over, even though you'd need only one continuation.

          • 10 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 →
              Abel supported this idea  · 
            • 6 votes
              Vote
              Sign in
              Check!
              (thinking…)
              Reset
              or sign in with
              • facebook
              • google
                Password icon
                Signed in as (Sign out)
                You have left! (?) (thinking…)
                3 comments  ·  F# Language  ·  Flag idea as inappropriate…  ·  Admin →
                Abel commented  · 

                It seems to me to make more sense to change the way you use DU for your problem domain. I am missing CFlat (C♭) and ESharp (E♯) etc, or things like DDoubleSharp (D

              • 7 votes
                Vote
                Sign in
                Check!
                (thinking…)
                Reset
                or sign in with
                • facebook
                • google
                  Password icon
                  Signed in as (Sign out)
                  You have left! (?) (thinking…)
                  0 comments  ·  F# Language  ·  Flag idea as inappropriate…  ·  Admin →
                  Abel shared this idea  · 
                • 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…)
                    3 comments  ·  F# Language  ·  Flag idea as inappropriate…  ·  Admin →
                    Abel commented  · 

                    @fsharporg-lang: The link to the suggestion "in favour of" is actually *this* suggestion. It seems that you mean to say you are actually going to implement this? Or did you mean to point to another suggestion?

                  Feedback and Knowledge Base