Sunday, November 18, 2007

I CAN HAS CLICK?!

I have been doing some basic hacking with F# today. It turns out Microsoft has made F# installable on Linux through Mono, which is absolutely amazing. I hacked up a small GUI program here. F# is a very cool programming language. Here is a breakdown of what the program does:
//This is the equivalent of #include/imports/using
open System
open System.IO
open System.Windows.Forms
open Printf

//Create the forms to be used
let main = new Form()

//Set the program attributes
main.Text <- "Main"
main.Visible <- true

//Start making the GUI for the main window
let menu = main.Menu <- new MainMenu()
let mnuFile = main.Menu.MenuItems.Add("&File")
let mnuAbout = main.Menu.MenuItems.Add("&About")
let mnuFile_Quit = new MenuItem("&Quit")
let mnuAbout_About = new MenuItem("&About")
mnuFile.MenuItems.Add(mnuFile_Quit)
mnuAbout.MenuItems.Add(mnuAbout_About)

//Start defining the callbacks and such
mnuFile_Quit.Click.Add(fun _ -> main.Close())
mnuAbout_About.Click.Add(fun _ -> printf "F# is cool!")
let btnOMFG = new Button()
btnOMFG.Dock <- DockStyle.Fill
btnOMFG.Text <- "I CAN HAS CLICK?!"
main.Controls.Add(btnOMFG)
btnOMFG.Click.Add(fun _ -> main.Close())

#if COMPILED
[]
do Application.Run(main)
#endif

I can't wait to start embedding this stuff into C# and VB, this coupled with LINQ will be equal to pretty much raw power.

No comments:

Post a Comment