I asked the following question on hubfs.net
This might be a newbie question about type inference, but it can help beginners like me.
I am using the query below – which sorts items by date. This gives the warning: This lookup uses a deprecated feature, where a class type is inferred from the use of a class field label…
Query.query <@ (Seq.sort_by (fun i -> i.DateAdded) (seq { for item in ctx.BarterItems do yield item })) |> Seq.take 50 @>;
In the seq { … } expression, the type of item is identified as “Item” correctly, through ctx.BarterItems. Why wouldn’t this be used to infer “i” in “fun i -> i.DateAdded“? ; Seq.sort_by being (<’a>-><’key>) -> seq<’a> -> seq<’a>
Explicitly identifying the type will remove the warning, as below:
Query.query <@ (Seq.sort_by (fun (i:Item) -> i.DateAdded) (seq { for item in ctx.BarterItems do yield item })) |> Seq.take 50 @>;
Brian McNamara pointed out:
let s = seq { yield “foo”; }
let s2 = s |> Seq.sort_by (fun x -> x.Length) // compiles
//let s2 = Seq.sort_by (fun x -> x.Length) s // does not
In the first one, we already know that the elements of ’s’ are type ’string’ by the time we reach the lambda body and “x.Length”. In the second one, we don’t. This is one of the things that makes the pipelining style so attractive.
As Brian pointed out, thats a good use case for the Pipelining operator.
My new query looks like:
Query.query <@ seq { for item in ctx.BarterItems do if item.ItemType = "book" then yield item }
|> Seq.sort_by (fun i -> i.DateAdded) |> Seq.take 50 @>;
Inference now works, since the type can be inferred left to right.
Meanwhile you can read more on ML type inference.
GrooveShark: The best internet radio service
April 8th, 2009
Just discovered GrooveShark. More that 7 million songs that could be played. Wow!
China blocks YouTube
March 24th, 2009
China blocks YouTube for some videos of the security forces beating up Tibetan monks. I remember last year they blocked SourceForge.net, the large Open Source software repository. All because one of the million sub-projects under SourceForge put up a Tibetan protest banner. Oh, they block Wikipedia too.
Don’t you just love the communists?
I am not Tibetan, and I know no Tibetans. But I myself wouldn’t want to live under such a repressive regime. FREE TIBET!
Windows Azure adds Full-Trust roles, F# becomes viable!
March 19th, 2009
Microsoft just announced some interesting enhancements to Azure, including Full-Trust roles. This makes life much better for anyone trying to use F# on Azure.
The earlier workaround requires adding more than 20 references, and takes 10 TIMES longer to get compiled.
George Carlin Collection
March 1st, 2009
The Ten Commandments
George Carlin on Death
Saving the Planet
What is wrong with this picture?
February 6th, 2009

Nothing really. I say the picture is Spot On!

Dear InterSystems, times they are a changin!
I suggest replacing the sports car with a Model T, though.
Frank Zappa!
January 15th, 2009

Acrylic on Canvas.
I am Free.
January 11th, 2009
This issue should resolve itself.
December 31st, 2008
Funny quote from Microsoft on ZuneInsider.
Q: What is Zune doing to fix this issue?
The issue should resolve itself.
Apparently, the bug becomes self-aware on Jan 1 2009. I am scared.
Woman in Clay
December 30th, 2008

Soft Pastels and Oil Pastels, Canvas.
Inspiration or Interpretation.
- Sphinx?
- Male organ?

