6 people like it.

Alternative ways to do some suggestions on F# user voice site.

I read all the suggestions on http://fslang.uservoice.com/ . They are great suggestions! I found some of then are realized well by using current language features. Then I introduce them.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66: 
67: 
68: 
69: 
70: 
71: 
72: 
73: 
74: 
75: 
76: 
77: 
78: 
79: 
80: 
// String Interpolation
// http://fslang.uservoice.com/forums/245727-f-language/suggestions/5678806-string-interpolation 
let (+@) a b = sprintf "%s%A" a b

let a = 40
let p = "John"
let b = " " + p + " has " +@ a*2 + " items"
printfn "%s" b


// Add Option.filter
// http://fslang.uservoice.com/forums/245727-f-language/suggestions/5674917-add-option-filter
module Option =
  let filter cond = 
    Option.bind(fun x -> if cond x then Some x else None)

let x1 = Some 1 
let x2 = Some 3 
let y1 = x1 |> Option.filter (fun i -> i = 3) // Returns None 
let y2 = x2 |> Option.filter (fun i -> i = 3) // Returns Some 3


// Allow the use of the tuple operator (,) as a function.
// http://fslang.uservoice.com/forums/245727-f-language/suggestions/5669324-allow-the-use-of-the-tuple-operator-as-a-funct 
let ``(,)`` x y = (x,y)


// F# 3.0 query expression with pipelined style
// http://fslang.uservoice.com/forums/245727-f-language/suggestions/5666371-f-3-0-query-expression-with-pipelined-style
open System.Linq
type Row = { ColumnA:int }
let source = [ for i in 0..9 -> { ColumnA = i } ]
source
  .OrderBy(fun a -> a.ColumnA)
  .Skip(10)
  .Take(20)
|> Seq.iter (fun a -> printfn "%s" (string a.ColumnA))


// Add syntactic sugar for functions ala Scala/Clojure
// http://fslang.uservoice.com/forums/245727-f-language/suggestions/5665355-add-syntactic-sugar-for-functions-ala-scala-clojur
type PlaceHolder () =
  static member (+) (__:PlaceHolder, right) = fun left -> left + right
let __ = PlaceHolder()
"Place" |> __ + "Holder" |> printfn "%s"


// Allow Pattern Matching on Types 
// http://fslang.uservoice.com/forums/245727-f-language/suggestions/5664335-allow-pattern-matching-on-types
open System
match typeof<float> |> Activator.CreateInstance with 
| :? int -> printfn "int!"
| :? float -> printfn "float!"
| _ -> printfn "didn't match!"


// Allow private constructors on DU cases 
// http://fslang.uservoice.com/forums/245727-f-language/suggestions/5663374-allow-private-constructors-on-du-cases
// ADDED: Mr @iceypoi kindly gived a better version of private DU constructor!
// URL: http://fssnip.net/ma
type EmailAddress = 
  | ValidEmail of string 
  | InvalidEmail of string 

[<AutoOpen>]
module Hide =
  type ``Don't use this! It's private constructor for the DU`` () = do ()
  module EmailAddress = 
    let ValidEmail = ``Don't use this! It's private constructor for the DU`` ()


// Allow custom equality on record types.
// http://fslang.uservoice.com/forums/245727-f-language/suggestions/5663332-allow-custom-equality-on-record-types
[<CustomEquality; CustomComparison>]
type Record =   
  { Field:string }
  override __.Equals (o:obj) = false
  override __.GetHashCode () = 0
  interface System.Collections.IStructuralComparable with
    member __.CompareTo (o:obj, _) = 0
val a : string
val b : 'a
val sprintf : format:Printf.StringFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
val a : int

Full name: Script.a
val p : string

Full name: Script.p
val b : string

Full name: Script.b
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
module Option

from Microsoft.FSharp.Core
val filter : cond:('a -> bool) -> ('a option -> 'a option)

Full name: Script.Option.filter
val cond : ('a -> bool)
val bind : binder:('T -> 'U option) -> option:'T option -> 'U option

Full name: Microsoft.FSharp.Core.Option.bind
val x : 'a
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
val x1 : int option

Full name: Script.x1
val x2 : int option

Full name: Script.x2
val y1 : int option

Full name: Script.y1
Multiple items
module Option

from Script

--------------------
module Option

from Microsoft.FSharp.Core
val i : int
val y2 : int option

Full name: Script.y2
val ( (,) ) : x:'a -> y:'b -> 'a * 'b

Full name: Script.( (,) )
val y : 'b
namespace System
namespace System.Linq
type Row =
  {ColumnA: int;}

Full name: Script.Row
Row.ColumnA: int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val source : Row list

Full name: Script.source
val a : Row
module Seq

from Microsoft.FSharp.Collections
val iter : action:('T -> unit) -> source:seq<'T> -> unit

Full name: Microsoft.FSharp.Collections.Seq.iter
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
Multiple items
type PlaceHolder =
  new : unit -> PlaceHolder
  static member ( + ) : __:PlaceHolder * right:string -> (string -> string)

Full name: Script.PlaceHolder

--------------------
new : unit -> PlaceHolder
val right : string
val left : string
val __ : PlaceHolder
val __ : PlaceHolder

Full name: Script.__
val typeof<'T> : Type

Full name: Microsoft.FSharp.Core.Operators.typeof
Multiple items
val float : value:'T -> float (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float

--------------------
type float = Double

Full name: Microsoft.FSharp.Core.float

--------------------
type float<'Measure> = float

Full name: Microsoft.FSharp.Core.float<_>
type Activator =
  static member CreateComInstanceFrom : assemblyName:string * typeName:string -> ObjectHandle + 1 overload
  static member CreateInstance<'T> : unit -> 'T + 15 overloads
  static member CreateInstanceFrom : assemblyFile:string * typeName:string -> ObjectHandle + 6 overloads
  static member GetObject : type:Type * url:string -> obj + 1 overload

Full name: System.Activator
Activator.CreateInstance<'T>() : 'T
   (+0 other overloads)
Activator.CreateInstance(activationContext: ActivationContext) : Runtime.Remoting.ObjectHandle
   (+0 other overloads)
Activator.CreateInstance(type: Type) : obj
   (+0 other overloads)
Activator.CreateInstance(activationContext: ActivationContext, activationCustomData: string []) : Runtime.Remoting.ObjectHandle
   (+0 other overloads)
Activator.CreateInstance(type: Type, nonPublic: bool) : obj
   (+0 other overloads)
Activator.CreateInstance(assemblyName: string, typeName: string) : Runtime.Remoting.ObjectHandle
   (+0 other overloads)
Activator.CreateInstance(type: Type, [<ParamArray>] args: obj []) : obj
   (+0 other overloads)
Activator.CreateInstance(domain: AppDomain, assemblyName: string, typeName: string) : Runtime.Remoting.ObjectHandle
   (+0 other overloads)
Activator.CreateInstance(assemblyName: string, typeName: string, activationAttributes: obj []) : Runtime.Remoting.ObjectHandle
   (+0 other overloads)
Activator.CreateInstance(type: Type, args: obj [], activationAttributes: obj []) : obj
   (+0 other overloads)
type EmailAddress =
  | ValidEmail of string
  | InvalidEmail of string

Full name: Script.EmailAddress
union case EmailAddress.ValidEmail: string -> EmailAddress
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
union case EmailAddress.InvalidEmail: string -> EmailAddress
Multiple items
type AutoOpenAttribute =
  inherit Attribute
  new : unit -> AutoOpenAttribute
  new : path:string -> AutoOpenAttribute
  member Path : string

Full name: Microsoft.FSharp.Core.AutoOpenAttribute

--------------------
new : unit -> AutoOpenAttribute
new : path:string -> AutoOpenAttribute
Multiple items
module EmailAddress

from Script.Hide

--------------------
type EmailAddress =
  | ValidEmail of string
  | InvalidEmail of string

Full name: Script.EmailAddress
val ValidEmail : Don't use this! It's private constructor for the DU

Full name: Script.Hide.EmailAddress.ValidEmail
Multiple items
type CustomEqualityAttribute =
  inherit Attribute
  new : unit -> CustomEqualityAttribute

Full name: Microsoft.FSharp.Core.CustomEqualityAttribute

--------------------
new : unit -> CustomEqualityAttribute
Multiple items
type CustomComparisonAttribute =
  inherit Attribute
  new : unit -> CustomComparisonAttribute

Full name: Microsoft.FSharp.Core.CustomComparisonAttribute

--------------------
new : unit -> CustomComparisonAttribute
type Record =
  {Field: string;}
  interface IStructuralComparable
  override Equals : o:obj -> bool
  override GetHashCode : unit -> int

Full name: Script.Record
Record.Field: string
Object.Equals(obj: obj) : bool
val o : obj
type obj = Object

Full name: Microsoft.FSharp.Core.obj
val __ : Record
Object.GetHashCode() : int
namespace System.Collections
type IStructuralComparable =
  member CompareTo : other:obj * comparer:IComparer -> int

Full name: System.Collections.IStructuralComparable
override Record.CompareTo : o:obj * Collections.IComparer -> int

Full name: Script.Record.CompareTo

More information

Link:http://fssnip.net/m9
Posted:10 years ago
Author:nagat01
Tags: language