Installing WP LaTeX

August 17th, 2010 matt Posted in Server | No Comments »

When I first started blogging I was really interested in having LaTeX equation support. After all, software development hasn’t always been my vocation – I did go to school for electrical engineering and have had my fair share of math classes :)

2 years ago getting LaTeX working within WordPress was incredibly difficult. It required installing ImageMagick, dvips, and a myriad of other tools on your hosting server. I asked Hostgator support if this was possible, only to be told an emphatic ‘no’ – the Linux VMs used to host my website were significantly sandboxed and this was not possible, so I gave up.

Fast forward to today – not only has WordPress made significant advances in update functionality – it is now trivial to add new plugins. What used to take hours on an SSH commandline now is possible with only a few clicks.

Here are the steps to follow:

  1. Log into the admin console and click on the Plugins tab.
  2. Click on Add New
    image
  3. Search for ‘latex’
  4. Find “WP Latex” in the list and click on ‘Install Now’:
    image
  5. Go to the Plugins tab, find ‘WP LaTeX’, and click ‘Active’

Now it’s just a matter of composing a blog post with equations embedded between image tags.

I like using Windows Live Writer for composing blog post, and this works perfectly. All that I need to do is create a new paragraph, enter the equation text in LaTeX, and then center align it (screenshot of WLW):

image

Here’s the rendered equation:

e^{i\pi}+1=0

Very cool. :)

AddThis Social Bookmark Button

On “Preinstalled Software” and “One Button Restore”

August 14th, 2010 matt Posted in Personal | 2 Comments »

Most laptop computers these days come with a number of “features” that drive me completely insane. Bear with me – I’ll try to stay calm :)

In particular – “preinstalled software” and “one button restore” are particularly egregious. My new Lenovo G555 is no exception.

The amount of preinstalled software was staggering. No, I don’t want to have facial recognition software protecting my computer from unauthorized logins. No, I don’t want identity theft protection management utilities from some software company I’ve never heard of. No, I don’t want silly wireless network control software that looks like it was written for a target audience of 6 year olds. No, I don’t want McAfee virus protection that only works for 30 days before it mercilessly hounds me with unending popups to pay for a subscription.

If the preinstalled pieces of software are not totally useless, they’re predatory. What’s the value in this from the consumer’s point of view? As a purchaser of a computer, I feel intense frustration with Lenovo for lessening the value of my purchase by installing a lot of things I don’t want, forcing me to spend my time cleaning things up to make my computer tolerable again. As for the predatory software, I feel “sold out” by Lenovo – they were probably able to “subsidize” the cost of my laptop hardware by letting 3rd-parties pay to install their programs on my machine. This is ridiculous!

As if this wasn’t bad enough, there is literally no way to remove all of the crapware to return to the original unmarred operating system. Sure, I could try to remove everything in the “Add/Remove Programs” dialog section of the Control Panel, but how could I be sure that the uninstallers actually removed everything? What if there are files and registry keys left – I don’t trust any of these software vendors (many of whom I’ve never even heard of) to do what I requested and not just leave backdoors behind.

After being foiled in that attempt, I tried to reinstall Windows 7. Oh wait, I can’t. I did not receive a Windows 7 DVD. My only option is to use the “one key recovery” button. What does this do? Oh, it just reverts the computer back to its original state, invasive crapware and all. No thanks.

My solution? Without any other options, the only workable solution is to go out and buy a brand new copy of Windows 7. This really irks me, seeing that I just paid for a perfectly good copy of Windows 7, but I can’t use it because Lenovo’s crappy “solutions” are getting in the way. Honestly? This is criminal, especially since there is no way to get a refund for the preinstalled copy of Windows 7.

So, after purchasing a new copy of Windows 7 (which wasn’t a total waste since I really want Ultimate instead of Home Premium), is it easy to install? No, of course not. The hard drive has special partitions to hold the one-key backup (in lieu of shipping the installation media). Really? Nothing on the website ever said “500GB* hard drive, * where you can’t use 25GB+ of the space because we’re too lazy to ship you installation media for the software you just purchased”. When did I give Lenovo permission to take some of the hard drive space that I just paid for to use for their misguided attempts in software distribution?

After blowing away these partitions (Shift+F10 during installation and diskpart overrides to the rescue) I was able to pave the machine and successfully install Windows 7 Ultimate.

What happened to the days where customers could buy hardware without all of this extra crap? Extra things (e.g. O/S, software, etc) should cost extra, and consumers should have a choice to purchase as little or as much as they need.

Sadly, this approach is not limited to Lenovo – I’ve had a similar experience with Dell and have heard horror stories from other consumers regarding other laptop vendors.

Has anyone else had a similarly frustrating experience?

AddThis Social Bookmark Button

The Blog is Back

August 14th, 2010 matt Posted in Personal | 1 Comment »

Well, it’s been awhile, but (hopefully), the blog is back. Why has the blog been dark for over a year?

I thought about it for awhile, trying to get to the real reason. The “no time” excuse got dismissed pretty quickly, since I had various small pockets of time that I could have used.  Similarly, the “nothing to say” argument fades away quickly since I’ve continued learning and exploring the new advanced in technology that have happened over the last year.

What’s the real reason? It might sound lame, but…the barrier to writing a post wasn’t low anymore. Why? The general pace of technology advancement simply outstripped my current computing capacity.  More specifically, new advances with Windows 7 and Visual Studio 2010 raised the hardware requirement bar so high that my 3-year-old Windows XP dual-core laptop couldn’t keep up.

Trust me, I tried. I waited 16+ hours for the installation(s) to finish, but the end result was a way-too-sluggish machine. 2GB of RAM just doesn’t cut it, and virtual memory off of a 5400rpm hard drive is doesn’t help much.

I guess this is to be expected – advances in software typically push the limits of available hardware (or is it the other way around?). This has always been evident in the high-end graphics card market.  I just found that the hardware requirement bar got pushed significantly faster these last few years due to Vista/Win7 and Visual Studio 2010.

So, the blog is back basically because I just got a new laptop :)

AddThis Social Bookmark Button

Great IoC and DI Articles

December 10th, 2009 matt Posted in Programming | 5 Comments »

I’ve been interested in learning more about Inversion of Control (IoC) and Dependency Injection (DI) containers for awhile now, so I decided to take a look.

My interest was piqued by an article by Mark Seemann from his upcoming book “DI in .NET”. This was a good introduction, but not very in-depth – I’m certainly looking forward to his book now. :)

After digging in more, I discovered a few more good articles (also on .NET Slackers) that explain IoC and DI using the Castle Project – “Inversion of Control and Dependency Injection with Castle Windsor Container” – check them out:

Very cool stuff.

AddThis Social Bookmark Button

F# Jobs on the Rise

June 19th, 2009 matt Posted in Programming | No Comments »

I’ve received 3 inquiries in the last 2 weeks as to my “job availability status”, all surrounding my experience with F# on my resume. I’m no longer looking for a job (thankfully) and thought I had removed all references to my resume from my website, Dice, Monster, etc.  I suppose there are still a few floating around somewhere.

I don’t know a lot of details about the positions these recruiters are trying to fill, but I did find out that one is in Columbus, OH and one is in Redmond, WA. In an effort to help out the F# community I figured I’d post about these jobs.  There’s nothing in it for me.

If you are interested, shoot me an email and I’ll send you the contact information for the folks who called/emailed/talked to me.

Here’s my info:

let email = 
    [(5,"gmail"); (2,"."); (3,"valerio"); (6,"."); (1,"matt");
     (7,"com"); (4,"@")]
    |> List.sortBy fst
    |> List.map snd
    |> List.reduce (^)

:)

AddThis Social Bookmark Button

Hunting the Elusive ‘tail’ Opcode in F#

June 18th, 2009 matt Posted in Programming | 1 Comment »

Awhile back I wrote a post about tail-call optimizations that the F# compiler used to eliminate stack overflows. Brian McNamera commented about another optimization that I didn’t illustrate – the ‘tail’ opcode that appears when mutually-recursive and indirectly-recursive functions are encountered. Tail-call optimization is one of the really powerful features of F#, so I really wanted to see how this worked under the hood.

The first thing we need is a pair of mutually-recursive functions.  The easiest (laziest? :) ) way to do this is to write one function (e.g. f1) and duplicate its implementation as another name (e.g. f2):

// Hunting for tail calls

 

// 6.17.09

 

 

 

open

System

 

 

 

let

rec sum1 n acc =

 

    match n with

 

    | 0 -> acc

 

    | _ -> sum2 (n-1) (acc+n)

 

 

 

and

sum2 n acc =

 

    match n with

 

    | 0 -> acc

 

    | _ -> sum1 (n-1) (acc+n)

 

   

 

let

sum n = sum1 n 0

 

 

 

let

main () =

 

   Console.WriteLine(“Hello”)

 

   printfn “%A” (sum 100000)

 

   Console.WriteLine(“Press Enter to continue…”)

 

   Console.ReadLine() |> ignore

 

   

 

main ()

 

After compiling this, I popped open the resulting executable in Reflector. Of course I wasn’t going to find the ‘tail’ opcode by looking at the C# – I needed to disassemble the IL. I hunted and hunted for the ‘tail’ opcode, but couldn’t find it!  Every call to f1 from f2 (and f2 from f1) used the stack to pass around n and acc. Even stranger – this is the first F# program I’d written using Visual Studio 2010, and I could have sworn that I’d done the same thing with F# in Visual Studio 2008 a couple months ago.

After building the project again, I noticed the command-line arguments passed to fsc:

—— Build started: Project: HuntingTailcalls, Configuration: Debug Any CPU ——

 

              C:\Program Files\Microsoft F#\v4.0\fsc.exe -o:obj\Debug\HuntingTailcalls.exe -g –debug:full –noframework –define:DEBUG –define:TRACE –optimize- –tailcalls- -r:”C:\Program Files\Microsoft F#\v4.0\FSharp.Core.dll” -r:”C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll” -r:”C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll” -r:”C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll” –target:exe –warn:3 –warnaserror:76 –vserrors –utf8output –fullpaths –flaterrors Program.fs

 

“—tailcalls-“? Somehow tailcalls are being turned off. Maybe there’s something in the project settings that are disabling the tailcalls? Ah-ha! The checkbox was unchecked :)

image

After poking around a bit more, I discovered that by default the “Generate tail calls” box is unchecked fo Debug mode, and checked by default for Release mode.  Hmmm, interesting.

After switching to Release mode, I rebuild the project and opened the .exe in Reflector.  Here we go! There’s the elusive ‘tail’ opcode:

.method

public static int32 sum1(int32 n, int32 acc) cil managed

 

{

 

    .maxstack 5

 

    L_0000: ldarg.0

 

    L_0001: switch (L_0019)

 

    L_000a: nop

 

    L_000b: ldarg.0

 

    L_000c: ldc.i4.1

 

    L_000d: sub

 

    L_000e: ldarg.1

 

    L_000f: ldarg.0

 

    L_0010: add

 

    L_0011: tail

 

    L_0013: call int32 Program::sum2(int32, int32)

 

    L_0018: ret

 

    L_0019: ldarg.1

 

    L_001a: ret

 

}

(The IL code for sum2 looks identical.) Interestingly enough, the C# code from Reflector looks exactly the same between Debug and Release modes (with and without tail calls) – C# doesn’t have the capability to make tail calls.

Well, there you have it! We finally found the elusive ‘tail’ opcode.

That being said, be sure to keep this in mind – the default settings of Visual Studio 2010 for F# development are drastically different between Debug and Release mode.  Bugs might crop up in Debug mode (e.g. StackOverflowExceptions) that don’t rear their heads in Release mode.

I think the motivation for this is that using tail calls severely limit the usefulness of the Visual Studio debugger since it relies on traversing the stack frame (that the tail opcode destroys) to display debugging information.

For example, without tailcall optimizations setting a breakpoint on sum1 looks like this:

image

image

The callstack shows some useful debugging information, specifically the values of n and the accumulator.

However, if we enable tailcall optimization, this breaks down after running through the breakpoint 10 times, each time it shows one line with different information:

image

image

… You get the idea.

Hope that sheds some light on tailcall optimization, as well as some of the new features of F# in Visual Studio 2010!

AddThis Social Bookmark Button

Hosting Subversion In the Cloud with Live Mesh

February 22nd, 2009 matt Posted in Utilities | 3 Comments »

This afternoon I was going back through some of the code I’d written for various blog posts that I’d kept in a Subversion repository.  During the move things have been in limbo and I haven’t had time to set up the SVN server again. I thought “Hmm, I wonder if I could host my Subversion repository in the cloud”.

Enter Live Mesh. It lets you add multiple devices to your mesh network and automatically synchronize your files between devices.  Pretty cool stuff.

At first I thought it would be a great place to put all of my source code — then I could have the code on every computer.  However, what if you have working code on your desktop, then open up the code on your laptop and introduce a few bugs.  When you go to open up the project on the desktop again, those bugs are there automatically.  The synchronization is great, but there’s no way to keep version information in case you want to revert to a previous snapshot of the files.

Anyone familiar with Subversion will remember that there are two main parts to an installation — the Subversion repository (could be local or remote) and another folder with the checked-out files. A not-uncommon setup for personal development work is to have a local Subversion repository as a directory on the local file system.  I wonder what would happen if I used slapped a local repository installation into a Live Mesh folder? Well, it would get automatically synchronized between machines. All devices in the network would have an SVN client installed (e.g. TortoiseSVN) and pointed to the Mesh-synchronized folder.  I think this just might work :)

For anyone interested, here are the steps that I followed to set this up.

Open up your Live Mesh Folders from My Computer:image

Set up a new folder named “Subversion”. Make sure that all of the devices in your Live Mesh network are set to “When files are added or modified” in the synchronization options.image

Browse over to the location (Subversion folder on my desktop), open it up, and create another folder inside called “Repository”.

Then, right-click on the Repository folder -> TortoiseSVN -> Create repository here. It’s important to note here that the extra “Repository” directory is important since you can’t directly create the repository in the “Subversion” folder one level up.  There is some interaction between TortoiseSVN and Live Mesh that keeps it from working.

Then, go back to the desktop (or any other place) and make a folder called “Checkout”.  Right-click on the Checkout folder and select “SVN Checkout…”

image

Make sure that the “URL of repository” field is pointed towards the “Subversion/Repository” directory and the “Checkout directory” field is pointed towards the “Checkout\Repository” directory and click OK.

There you go — use the checked-out subversion repository as you wish and just point your SVN client on each device to the Mesh-synchronized folder.

Hope someone finds this useful! :)

UPDATE: Looks like I’m not the first to think of doing this :)

AddThis Social Bookmark Button

Big Changes

February 5th, 2009 matt Posted in Personal | 2 Comments »

The blog’s been pretty quiet lately for good reason — I simply haven’t had a spare second to post anything. I have quite a few interesting posts in the wings just waiting for a last bit of polishing.

Why so busy?  Well, since the end of November I applied for, interviewed for, was offered, and accepted a job at Microsoft :)   As a consequence, I’ve been extremely busy getting ready for and making the cross-country move from Columbus, OH to Redmond, WA.  Needless to say, it was a very exciting and nerve-wracking last few weeks.

I started as a SDE (software development engineer) in the Health Solutions Group last Monday. I’m still learning the ropes and certainly relate to the feeling of “drinking from the fire hose“. Today was a “momentous” occasion as I submitted my first bugfix, only to quickly discover the need to submit a bugfix for my bugfix. It’s quite humbling being completely surrounded by veritable developer rockstars.

Despite all of the stress, I am absolutely and totally pumped to be here — my project is awesome and the people I work with are awesome — there are very exciting times ahead :)

Hopefully as things start to settle down I’ll get some time to braindump about all of the cool things going on. :)

AddThis Social Bookmark Button

Recursion in F# and the Tail Recursion Police

January 5th, 2009 matt Posted in Programming | 2 Comments »

A helpful comment on a post over at HubFS by Brian McNamara really helped me wrap my mind around tail recursion and why it’s immensely important to understand in F#. Brian coined the phrase “tail recursion police”, hence the title :)

Recursion pops up quite a bit in functional programming so it’s a good idea to understand the risks/tradeoffs/benefits. A gross simplification of an analogy would be:

For loops : C# :: Recursion : F#

Sure, you can do for-loops and imperative-style coding in F#, but it doesn’t showcase the beauty of the functional style programming that F# offers.

Recursive functions (in both C# and F#) are just functions that call themselves.  They do so by pushing the current state of the function onto the stack, popping them off when calls start completing. Because the stack is a limited resource, it can be exhausted (StackOverflowException) if the function is called recursively too many times. 

These kinds of runtime exceptions can be difficult to find unless explicitly tested for, leading to hard-to-find bugs.  Oftentimes tests will only exercise simple cases of algorithms and then fail at runtime when large (real-world) inputs are used. After all, “everything works for small N”.

F#, however, has a very interesting feature where (under certain conditions), it can recognize recursive functions and perform a “tail call optimization”, turning the recursive function into a while-loop that uses no stack space whatsoever. This is called tail recursion.

The rule for tail-recursion is simple:

If the recursive call to the function is the very last thing that happens in the algorithm, then the function can be made tail-recursive.

In most cases a recursive algorithm can be expressed in both recursive and tail-recursive forms. Other times, it may not even be possible to implement a specific algorithm tail-recursively.

Let’s look at some examples.

Tail Recursive or Not?

One way to implement the “map” function that applies a specific function, f, to every element in a list would be:

let rec map f l =

  match l with

  | [] -> []

  | h::t -> f h :: map f t

While this implementation easily expresses the algorithm (splitting a list into its head and tail, applying the function f to the head, and consing it to the list obtained from applying the function to the tail), it is NOT tail recursive! The recursive call to “map” must happen, then f is applied to h, and then the results are cons’d (:: operator).  The recursive call to “map” is not last in this instance, so it’s not tail-recursive.

How can we make this map operation tail-recursive? Typically this involves 2 things — factoring out an inner loop that is recursive and threading an accumulator through that inner loop:

let mapTR f l =

  let rec loop f2 l2 acc =

    match l2 with

    | [] -> acc

    | h::t -> loop f2 t ((f2 h)::acc)

  loop f l [] |> List.rev

In the 2nd-to-last line, f2 is applied to the head, then cons’d with the accumulator, and that result (along with f2 and the tail) are passed to the recursive call to “loop”.  In this case, “loop” is the very last thing that happens, so the F# compiler can implement this tail-recursively.

Double-Check with Reflector

We can double-check that the F# compiler created a recursive function for the “map” case by using Reflector.  While F#-compiled-to-IL-decompiled-to-C# can be a bit verbose thanks to all of the generics and partial function application (FastFunc), it can still be seen that the map function recursively calls itself.

image

If the Tail Recursion Police were out, we’d be totally busted.

For the “mapTR” case, the implementation is a bit hidden behind some closures, but can be found with a little work.  The meat of the tail-recursive function is implemented with a while(true) loop! This is fantastic since it uses no stack space. The Tail Recursion Police would let us off clean on this one.

image

Sidenote: The List<T> type here is not the standard System.Collections.Generic.List<T>.  It is a singly-linked list that is part of the F# core libraries. In F# the Generic.List<T> is known as ResizeArray<T> since it more resembles a resizable array than a singly-linked list.

Sidenote 2: I’ve heard some things about the “.tail” IL opcode, but don’t see it popping up anywhere in this code. The while loop seems more efficient to me than a recursive call that drops the current stack frame, though. I’m not entirely sure what the relationship is between the .tail opcode is and tail recursion in F#.

Let’s walk through another example and dig into a little more detail.

Kaboom! StackOverflowException Strikes

When working on some code over the weekend, I ran into the need for a slightly different version of List.map. The “map” function has the signature “(‘a -> ‘b) -> ‘a list -> ‘b list” — that is, it takes a function that takes a ‘a and returns a ‘b as well as a ‘a list to operate on, producing a ‘b list. It simply applies the given function to each item in the list and returns a new list with the result of each function application.

What I needed, however, was a method that took a list of one type and returned a list of another type, but applied a function that accepted a list of values and produces a resulting value.  That is, I needed a function with a signature “(‘a list -> ‘b) -> ‘a list -> ‘b list”. When you think about this, I needed an algorithm that would operate on the initial list by calling a method by “snapping off” successive portions of the list, producing another list.  So, if we had a list [1;2;3;4], the mapping function would be called in succession with input lists [1;2;3;4], [2;3;4], [3;4], [4], and []. Since it’s still doing a mapping, though making the entire list (instead of just the head of the list) available to the mapping function, I decided to call it “mapl” for “map list”.

My first stab at an implementation was straightforward:

module List =

  let rec mapl f l =

    match l with

    | [] -> []

    | h::t -> f l :: mapl f t

 

> let test = [1;2;3;4];;

val test : int list

 

> test |> List.mapl (printfn “%A”);;

[1; 2; 3; 4]

[2; 3; 4]

[3; 4]

[4]

Good so far. However, it’s not tail-recursive, so let’s see if we can break it:

> [1..100000] |> List.mapl List.hd;;

 

Process is terminated due to StackOverflowException.

Session termination detected. Press Enter to restart.

image

Kaboom! The Tail Recursion Police are already on the scene, cleaning up the remains of fsi.exe…

Tail-Recursion Tweaks and Performance

Ok, so let’s make this “mapl” function tail-recursive. I wanted to investigate 3 different approaches and compare the performance based on slight nuances between the implementations.

Here’s my code for mapl_tr1, mapl_tr2, and mapl_tr3:

module List =

  let mapl_tr1 f l =

    let rec loop l2 acc =

      match l2 with

      | [] -> acc

      | h::t -> loop t ((f l2)::acc)

    loop l []

 

  let mapl_tr2 f l =

    let rec loop f2 l2 acc =

      match l2 with

      | [] -> acc

      | h::t -> loop f2 t ((f2 l2)::acc)

    loop f l []

 

  let mapl_tr3 f l =

    let rec loop (f2, l2, acc) =

      match l2 with

      | [] -> acc

      | h::t -> loop (f2, t, ((f2 l2)::acc))

    loop (f, l, [])

You can see that we factored out an inner loop that is recursive, added an accumulator list, and made sure that the loop function call was the last operation before recursing.

  • mapl_tr1: This function captures the function “f” (a closure) from within the inner loop.
  • mapl_tr2: This function explicitly passes the function “f” to the inner loop to test if a closure slows things down
  • mapl_tr3: This function creates tuples when passing values to the inner loop and recursing to test if tuples are faster than partial function applications

To test these functions out, I used a simple test harness:

let main () =

  printfn “Tail Recursion Test”

  let run_test m =

    time_iter 10 (fun () -> [1 .. 100000] |> m List.hd |> ignore)

  let methods = [List.mapl_tr1; List.mapl_tr2; List.mapl_tr3]

  let names = ["mapl_tr1"; "mapl_tr2"; "mapl_tr3"]

  methods

    |> List.map run_test

    |> List.zip names

    |> List.iter (fun i -> printfn “%s: %f ms” (fst i) (snd i))

  press_enter ()

This takes a list of the three methods (isn’t it great to pass around code as data in functional languages?), run a test by timing it and taking the average of 10 executions, then print out the results.

Tail Recursion Test

mapl_tr1: 46.616836 ms

mapl_tr2: 42.788645 ms

mapl_tr3: 65.175500 ms

Press Enter to continue…

Wow, that’s really interesting. mapl_tr1 and mapl_tr2 are almost the same running time, but mapl_tr2 is slightly faster.  So we can conclude that the closure adds a very small amount of overhead, which isn’t surprising.  What caught me off guard is that mapl_tr3 takes more than 50% longer than mapl_tr2, owing to the constant creation of tuple objects under the hood. Looks like we have a winner, mapl_tr2!

For completeness, the implementations of time_iter and press_enter are given below:

#light

 

open System

open System.Diagnostics

 

let press_enter () =

  printfn “Press Enter to continue…”

  Console.ReadLine() |> ignore

 

let time f =

  let sw = new Stopwatch()

  sw.Start()

  f ()

  sw.Stop()

  sw.Elapsed.TotalMilliseconds

 

let time_iter n f =

  [0 .. n]

  |> List.map (fun _ -> time f)

  |> List.average

(time_iter can be optimized so it doesn’t create a 0..n list and uses sequence expressions…)

Conclusions

F# makes it really easy to write recursive functions that succinctly express our algorithms, but care must be taken to address tail recursion so that StackOverflowExceptions aren’t encountered in production code. Also, tail-recursive functions can be further optimized by ensuring that tuple objects aren’t created at each iteration, and by explicitly passing functions to inner loops and not relying on closures.

Whenever you write “let rec”, don’t give the Tail Recursion Police reason to take you downtown…

Hope that helps someone and eliminates some of the smoke/mirrors surrounding tail recursion!  :)

AddThis Social Bookmark Button

Assembly Information for F# Console Applications

January 4th, 2009 matt Posted in Programming | No Comments »

Right on the heels of my last post about an AssemblyInfo.fs file for F# Libraries (DLLs), we can do the same thing for F# console applications with a slight modification.

The default F# console application contains a single Program.fs source file. By default, this puts everything in that file into a module named “Program”.

The entry point of an F# console application is typically the top-most code in the last .fs file of the project.  This leads to the standard F# programming pattern of the last file in the project (typically Program.fs) containing something along the lines of:

let main () =

  …

 

main ()

Now, to add all of the assembly metadata to the project, we need to attribute the “main ()” function call with all of the attributes.  We can’t use the “unit” operator “()” like we did in the F# Library case, since our console application actually does have an entry point that we care about.

We can accomplish this by moving the “main ()” line to the AssemblyInfo.fs file, requiring us to fully-qualify it to “Program.main ()” since it resides in the Program module.

If we add the AssemblyInfo.fs file from the previous post, it must go last, for example:

image

Now, in Program.fs we only have:

let main () =

  …

And at the end of AssemblyInfo.fs we have:

[<assembly: AssemblyVersion("1.0.0.0")>]

[<assembly: AssemblyFileVersion("1.0.0.0")>]

Program.main ()

Just like in the library case, it would be nice if the default F# console application template included both Program.fs and AssemblyInfo.fs and included a definition for “main” to avoid any confusion as to the entry point of the application.

Hope that helps!

AddThis Social Bookmark Button