Friday, January 16, 2009

A forward pipe (“ |> ”) operator in Scala

One of the addictive things from F# is the |> operator defined by

but I've not yet found an equivalent in Scala, even though there are a ton of useful things given by the built-in APIs -- for example, I've not had to implement the usual abstraction to manage an (array, offset, length) combination, when there's Array.slice() there already.

So, just for fun...

with unit test

Refrigerator logic — I later realise that without actually adding any variance annotations the piped-to function can be one that takes any super-class of the value type. A little more thought suggests to me that type-inference does that automagically because it is able to reconcile all inputs into the types in that single expression, and will force the value to the supertype in order to make everything match up.

Thursday, January 08, 2009

Old-fashioned winter

After a dull near-freezing weekend, there was snow lying on Monday morning, in a day of sunshine and showers.

Tuesday, bright, sunny and sub-zero; so when we went on the weekly lunchtime walk, rather than staying on paved ways, we came to the bridlepath that has been too muddy all last year, and it was white with firm trodden-down snow. So we made an unexpected off-piste diversion.

Wednesday was back to about freezing, and dull, leaving lots of slush in shaded places; today, the same.

Links for 8-Jan

PoSh -- an effective foreach idiom.

PoSh -- Boots for WPF GUIs (inspired by Ruby Shoes).

C#3 and currying (series).

Ultimate List of Free Windows Software from Microsoft!

Monday, January 05, 2009

Timestamping F# assembly versions

Following up to the previous post, with this script Timestamp.fsx (unchanged by the Feb 2010 CTP, but enhanced to show the current year when it is no longer 2009):

suitably adjusted to taste in your main project folder, and a pre-build step of

cd ..\..
"C:\Program Files\FSharp-1.9.6.2\bin\fsi.exe" --exec Timestamp.fsx

or in the Feb 2010 CTP

cd ..\..
"C:\Program Files\FSharp-1.9.9.9\bin\fsi.exe" --exec Timestamp.fsx

you can get an automatically timestamped assembly, as per a C# 1.0.* version.

Note that using [< assembly: AssemblyVersion(\"1.0.*\") >] gives an assembly version of 0.0.0.0 in the DLL manifest, and no file version whatsoever.

You will have to bootstrap the process by creating a dummy AssemblyInfo.fs, and adding it to the project -- but of course not checking it in to source control or anything like that, since it is recreated every build.

Later: If the 4th facet exceeds 32k, it ends up set to zero, so change the factor to 3 in let revision= ((int fraction.TotalSeconds) / 3) for those end-of-UTC-day builds...

Links for 5-Jan

Just a small selection from the last week or so, and not even trying to keep up with PoSh v2CTP3 goodness -- I will be so pleased when that gets to go-live state!

AssemblyInfo.fs usage for F# DLLS and console executables. Note that the ability to default build and revision numbers as in [<assembly: AssemblyVersion("1.0.*")>] is not provided for you -- time-stamping has to be done externally e.g. by a pre-build step.

Generics in XAML.

Avoiding deadlocks when redirecting stdin/out/err for spawned processes in .Net code.

Speech recognition with .Net 3 and speech synthesis too!

Thursday, January 01, 2009

The first day of the rest of my life

After a good week last week, Karen's MS has really bitten her these last few days, both physically and mentally. On the bright side, it is the first real attack, rather than just slow progression, for a long while. Still, it looks like I'm going to have to pretty much everything about the house and more body-servant work while getting some formal assistance involved.

All this and work too, tomorrow.

2008 in media -- retrospect

Film : apart from the handful at the Film Festival, cinema seemed to be either the standard extruded product from the bowels of Hollywood, or English-miserablist. The only one I saw was when taking Karen to see Georgiana, and that I didn't rate.

Books : almost everything I read was software related -- for SF, see above about extruded product. My recommendation on the software front would be F# for Scientists, which did the basic teaching necessary to make the other books (Foundations of..., Expert...) somewhat more comprehensible. Foundations in particular is a poor introductory text as it hides the descriptions of syntax (as opposed to accidents of the examples) in solid paragraphs of text -- you need to have grasped the language before you can really get to grips with the book.

Anime : the year when Aniplex hired an outfit to send out DMCA notifications, where fansubs were slow, but some titles were for the first time officially simulsubbed or nearly so (of which only Strike Witches took my fancy). A fair number of OK-to-good series from the middle of the year, but nothing as outstanding as '07.

No real highlight, unless Mouryou no Hako delivers as it has begun, and only one that was so bad that I regretted having watched the one episode (Mnemosyne); though quite a lot that failed out of boredom (Spice & Wolf, Shigofumi Telepathy Girl Ran).

Other titles get separate mentions earlier, or get covered in spring and summer round-ups.

F# CTP and Silverlight 2 redux

Following up from here.

Units of measure are indeed useful, especially once one has twigged that the syntax needed to generalize over the units involved is like

and that you need to go the F# built-in math functions to have ones that are themselves so generalised.

So, here is the mostly essentially finished example applet (still needs to compute and draw the moon phases) with source bundled into the .xap file