F# for heating

Sometimes, when you feel really alone and want a bit of heat then F# can help you here.

All you need is a laptop and F#. Just type the following snippet into FSI and wait for a minute. =)

[|1..999|] |> Array.Parallel.iter (fun _ ->
    while true do ignore())

Wish you warm Christmas!

P.S. The same solution works when you are freezing.

8 thoughts on “F# for heating

  1. Can you help to write efficient code in F# to achieve following.
    — connect to database and get dataset
    — prepare my object (i.e Person(){firstname, lastname) from this data and create a List of Person object.

    — Now whenever I need to access person details i read it from this collection. No more calls to database

    In My code i have achieved to do all of them except the last point. Every time i access Person object its going to database and reload the data😦

    thanks in advance. is there any personal email address from you so i can contact you about some of the implementation in F# i am working on

    many thanks in advance🙂

  2. thanks for the reply . Here is my code below.
    module sql
    open System
    open System.Collections.Generic
    open System.Data
    open System.Data.SqlClient
    open System.Reflection
    open System.Data.OleDb;
    open System.Text.RegularExpressions
    open Microsoft.FSharp.Reflection

    // Using records to store the data
    type Person = { FirstName:string; LastName:string; Age:int }

    let connectionString= “myDBConnectionstring”
    // Runs the specified query ‘sql’ and formats rows using function ‘f’
    let query sql f =

    seq { use cn = new SqlConnection(connectionString) // will be disposed
    let da = new SqlDataAdapter(new SqlCommand(sql, cn))
    let ds = new DataSet()
    let i = da.Fill(ds)
    let rowCol = ds.Tables.[0].Rows
    for i in 0 .. (10 – 1) do // just take 10 records for test
    yield f (rowCol.[i]) }

    let names = query “SELECT * FROM User_tbl” (fun row -> row.[“FirstName”])
    for name in names do printfn “%A” name

    names |> Seq.iter (printfn “%A”)

    Now when i access objects from “names” than its accessing the database (which i understand why as my code is written like this )
    i want to load it once only.

  3. Hello
    Is there something called Eval or similiar function available in F# ? i have already looked on community but could not really get a clear direction.
    Here is what i want to achieve

    type Parameter = { Paramkey:string; ParamFormula:string; ParamDefaultValue:int }

    let p1 = { Paramkey = “p1”; ParamFormula = “10”; ParamDefaultValue = 10; }
    let p2 = { Paramkey = “p2”; ParamFormula = “p1*2”; ParamDefaultValue = 20; }
    let p3 = { Paramkey = “p3”; ParamFormula = “10+(p1*3*p2)”; ParamDefaultValue = 30; }

    let ParameterList = [p1;p2;p3]
    let Formula1 = p1.ParamFormula + p2.ParamFormula +p3.ParamFormula

    let Formula2 = Formula1*10

    call Formula2

    the parameter formulas will be coming straight from some datastore .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s