A Twitter search client in 10 lines of code with F# and the JSON type provider

This is very cool

Advertisements

Interface in F#

module interfaceexample

type IMyFSharpInterface=
abstract member memberWithOneInput : int ->unit
abstract member memberWithTwoInput : int -> float->unit

 

type MyFSharpInterfaceImpl()=
interface IMyFSharpInterface with
member this.memberWithOneInput x = printfn “I am memberWithOneInput implementation”
member this.memberWithTwoInput x y = printfn “I am memberWithTwoInput implementation”

let classobject =new MyFSharpInterfaceImpl()
let a = (classobject:>IMyFSharpInterface).memberWithOneInput 1
let ab = (classobject:>IMyFSharpInterface).memberWithTwoInput 1 2.5

Read and Parse file in F#

Sample code 

open System.IO
open System

let ParseFile =
let fileData = File.ReadAllLines(@”C:\temp\log.log”)

let LookForErrors =
fileData
|> Seq.filter(fun x -> if x.Contains(“error”) then false else true)

let LookForWarning =
fileData
|> Seq.filter(fun x -> if x.Contains(“warning”) then true else false)

let mynewfiledata =
let mynewfiledata = Seq.append LookForWarning LookForErrors
let FileSummary = “Number of Entries : ” + fileData.Length.ToString() + ” Number of Errors : ” + (LookForErrors |> Seq.length).ToString()
Seq.append ( FileSummary |> Seq.singleton) mynewfiledata

File.WriteAllLines(“c:\\temp\Test.txt”, mynewfiledata)

First hand experience with F#

I have been studying F# lately and more I read more i fall for functional programming languages.

I have also developing a REST service over last few weeks using Service Stack framework for restfull services in  C#.

To play around with F# i have decided to migrate my same service from C# to F# with ServiceStack  itself .

Below 3  new things for me to explore  at same time

  • — Differences between F#2.0 and F# 3.0
  • — first hand functional programming experience
  • — F# with Service Stack ( console hosting)

Below are are the outcomes of my migration:

  • Clear code
  • Less code about 60% less code
  • No hit and trial , code worked in first compilation
  • Faster development time (over 50% gain)

I will explore more and hopefully i choose this as main programming language for my upcoming Large size project.

Resources for F#

TryF#

http://msdn.microsoft.com/en-us/vstudio/hh388569.aspx

http://fsharpforfunandprofit.com/

http://sergeytihon.wordpress.com/tag/f/