Thursday 6 February 2014

Type Annotations in F#

In this article we are going to see the Type annotations in F#, Type annotations is specify the type in the input parameter.if we are not specify the Type then the function can't able to find which type is this to do operations like replace in string.

#light
 
open System.Data.SqlClient
open Microsoft.FSharp

let rep pharse =
pharse.Replace('t','7').Replace('o','0')



Now compiling above code shows error that not able to find the correct type, because the usage of Replace function we have to specify the Type as Annotation so the above code is reformatted.


#light
 
open System.Data.SqlClient
open Microsoft.FSharp

let rep (pharse:string) =
pharse.Replace('t','7').Replace('o','0')

 Output:
   rep token ;;
   70ken

From the above code you can learn the Type annotation in F#.



No comments:

Post a Comment