Just curious--why would you bother to redefine the "ignore" keyword? Less typing?

By on 6/8/2010 5:09 PM ()

My personal preference when heavily using e.g. 'StringBuilder' or other 'fluent' interfaces that 'return this' is to define a helper method, a la

let sb = new StringBuilder()

let Append (s:string) = sb.Append(s) |> ignore

...

Append("foo")

Append("bar")

(Alternatively, one could define extension methods like sb.AppendIgnore("foo") maybe.)

When just using such APIs lightly or in passing, I bite the bullet and sprnkle a handful of "|>ignore"s into the code.

By on 6/8/2010 5:16 PM ()

1) Why don't you use a SQL join instead of a lot of queries for different values of make?

2) Abandon imperative datastructures (.NET List) and embraaaace Functional ones (F#'s list).

3) Supposing you use a join, and you get a datatable with all the models and makes you can collect all models with

1
2
    let dt = someDataTable
    let models = dt.Rows |> Seq.cast<System.Data.DataRow> |> Seq.map (fun dr -> (dr.["Model"].ToString()))

or even better, into a dictionary Make -> list of models:

1
2
3
4
5
6
    let dt = someDataTable
    let models = dt.Rows
                    |> Seq.cast<System.Data.DataRow>
                    |> Seq.map (fun dr -> (dr.["Make"].ToString(), dr.["Model"].ToString()))
                    |> Seq.groupBy fst (* Make *)
                    |> Map.ofSeq

My first F# groupBy [B]

By on 6/7/2010 3:20 PM ()

1) Why don't you use a SQL join instead of a lot of queries for different values of make?

2) Abandon imperative datastructures (.NET List) and embraaaace Functional ones (F#'s list).

3) Supposing you use a join, and you get a datatable with all the models and makes you can collect all models with

1
2
    let dt = someDataTable
    let models = dt.Rows |> Seq.cast<System.Data.DataRow> |> Seq.map (fun dr -> (dr.["Model"].ToString()))

or even better, into a dictionary Make -> list of models:

1
2
3
4
5
6
    let dt = someDataTable
    let models = dt.Rows
                    |> Seq.cast<System.Data.DataRow>
                    |> Seq.map (fun dr -> (dr.["Make"].ToString(), dr.["Model"].ToString()))
                    |> Seq.groupBy fst (* Make *)
                    |> Map.ofSeq

My first F# groupBy [B]

By on 6/8/2010 9:02 AM ()

I don't mean to bust your chops, but the following code doesn't work.

Error is:

Error 33 The operator 'expr.[idx]' has been used an object of indeterminate type based on information prior to this program point. Consider adding further type constraints C:\Code\Gamit2009\HMTDMT\HumFS\ListMatching.fs 44 62 HumFS

let mutable dtMakes = new DataTable()

let dt = dtMakes

let MakeRows = dt.Rows |> Seq.cast |> Seq.map (fun dr -> dr.["Model"].ToString())

By on 6/8/2010 11:32 AM ()

My original code has Seq.cast<DataRow>.

By on 6/8/2010 12:00 PM ()

heh, I thought you just copy and pasted your original to the second post :D

he he

By on 6/8/2010 12:26 PM ()

thanks for the info Mau. My goal is to take each make and make a list of all the models in each make and sort the list of each model (assign a sort seq) to each (make model) pair, but the list has to be sorted by model of each make.

Also the sorted Model is not "string" sorted, in c# I use an Icomparer to accomplish my specialized sorting.

Numbers come after letters, spaces are sorted first so:

F Series would come before

Fiesta

All the Makes are sorted (regular).

The goal is to update pub_makemodellst with a "model sortseq"

Given that having 2 lists of makes and models where I can iterate through makes to get each model list

sort the model list

and run an update query to populate a sort sequence for each model so that when I run this query:

select make, model, sortseq from pub_makemodellst order by make, sortseq

The records come back sorted.

By on 6/7/2010 4:59 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper