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.
Discover more from Sergey Tihon's Blog
Subscribe to get the latest posts sent to your email.
this is really cool 🙂
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 🙂
It is really depend on the database that you use. If you use SQL for example, you should use SqlTypeProvider. If you use Mongo, then Fsharp.Mongo will be good choice. Please share a bit more details.
BTW. StackOverflow http://stackoverflow.com/questions/tagged/f%23 is great place for questions, there are lot of experts there.
Reblogged this on D Says and commented:
This is a real fun and let your frustration go out from your computer.
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()
cn.Open()
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.
It is happened because the sequence is lazy. Please try to load it into list or array, like this
let names = query “SELECT * FROM User_tbl” (fun row -> row.[“FirstName”]) |> Seq.toArray
But, much shorter code will be with TypeProviders
http://msdn.microsoft.com/en-us/library/hh361033.aspx
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 .