Monadic Philosophy

(Since I accidentally published part one of this series a few minutes ago, I figured I might as well start publishing the series.)

If you start learning functional programming, eventually you’ll come across the idea of a monad. Coming from the object/imperative world of languages like C#, I’ve had a hard time wrapping my head around this concept. There’s no shortage of monad tutorials out there, but most use Haskell’s IO as the prototypical example of a monad. Given that I don’t know Haskell very well, I found it hard to separate the Haskell stuff from monad stuff. So I set monads on the back burner and decided not to worry about them.

However, all that changed when Stephan Tolksdorf alerted me to his very cool monadic parser combinator library FParsec. I found the FParsec parsers much easier to read my F# parser efforts, so I became very interested in monadic parser combinators. As you might guess, a “monadic parser combinator library” makes heavy use of monads. Time to switch burners.

The problem with learning monads with FParsec is that it’s really designed for production use. I needed to break monads down to first principles, so I rolled my own monadic parser library. Make no mistake, if I were looking to build a production parser in F# right now, I’d use with FParsec. My monadic parser library might “get there” eventually, but right now it’s a toy.

Over a series of posts, I’m going to describe what I know about monads. I didn’t set out to write a tutorial on monads – as I said, there are plenty of them out there. However, I found most of the the many monad tutorials I read lacking because the did a good job explaining the “how”, but not such a good job on the “why”. Coming from an imperative world, I wanted to understand the philosophy better. That being said, there’s a lot of tutorial in and around the philosophy. Hopefully, you’ll find both useful.

Programming Languages @ PDC08

The PDC folks pushed out a bunch of new sessions yesterday, including a bunch from my part of DevDiv. You can see the full list of sessions that have been published (so far) at the PDC site.

An Introduction to F#
Learn about Microsoft’s new language, F#, a typed functional programming language for the .NET Framework. F# combines functional programming with the runtime support, libraries, tools, and object model of .Net. Understand how F# asynchronous workflows help tame the complexity of parallel and asynchronous I/O programming and how to use F# in conjunction with tools such as Parallel Extensions for .NET.

Deep Dive: Dynamic Languages in .NET
The CLR has great support for dynamic languages like IronPython. Learn how the new Dynamic Language Runtime (DLR) adds a shared dynamic type system, a standard hosting model, and support for generating fast dynamic code. Hear how these features enable languages that use the DLR to share code with other dynamic and static languages like VB.NET and C#.

Future Directions for Visual Basic
Come learn about the new capabilities in the next version of the language, including: extensions to LINQ, syntax simplifications, and improvements to the IDE. We’ll provide insight into the direction of the language, including dynamic binding, meta-programming, and scripting.

The Future of C#
In this talk Microsoft Technical fellow and C# Chief Architect Anders Hejlsberg outlines the future of C#. He will describe the many forces that influence and shape the future of programming languages and explain how they fit into C#.

Visual C++: 10 is the New 6
Get more done. The next version of Visual C++ is all about improving developer productivity for large-scale applications. Learn about the IntelliSense and browsing experiences, changes to the project and build system, project-less browsing, collaboration through remote symbol indexing, and custom visualization of symbolic information.

WebDev.WebServer PowerShell Function

In experimenting with NWSGI yesterday, I found I wanted the ability to launch the development web server that ships with Visual Studio (WebDev.WebServer.exe) from the command line. I hacked up the following PowerShell function and dropped it into my $profile so I can easily launch the web server in any directory any time I need. Thought I’d share:

function webdev($path,$port=8080,$vpath='/')
{
    $spath = 'C:\Program Files\Common Files\microsoft shared\DevServer9.0\WebDev.WebServer.EXE'
    $rpath = resolve-path $path  
    $params = "/path:`"$rpath`" /port:$port /vpath:$vpath"  

    $ignore = [System.Diagnostics.Process]::Start($spath, $params)  
    "Started WebDev Server for '$path' directory on port $port"  
}

There’s probably an easier way to launch an exe with parameters than Sys.Diags.Process.Start, but it works. Using resolve-path is the key, that lets me pass in a relative path on the command line, but the script converts it to an absolute path in order to pass it to the webdev server. Also, I’m not sure I should have hard coded the path to the exe, but again it works and it’s not like it’s tough to change.

Enjoy.

Update: Tomas Restrepo pointed out an easier way to start the process:

&'C:\Program Files\Common Files\microsoft shared\DevServer9.0\WebDev.WebServer.EXE' "/path:$rpath" "/port:$port" "/vpath:$vpath"

I couldn’t figure out how to correctly launch the exe when the physical path to serve has a space in it. Thanks Tomas.

Morning Coffee 141 – Lang.NET ’08 Edition

header

I was hoping to blog my thoughts on Lang.NET as the event went along. Obviously, that didn’t happen, though I was pretty good about dumping links into my del.icio.us feed. The talks were all recorded, and should be up on the website in a week or two. Rather than provide a detailed summary of everything that happened, here are my highlights:

  • The coolest thing about conferences like this is what John Rose called “N3″ aka “Nerd-to-Nerd Networking”. It was great to meet in person, drink with and geek out with folks who’s blogs I read like Tomas Petricek, Wesner Moise and Larry O’Brien. Plus, I got to meet a bunch of other cool folks like Gilad Bracha, Stefan Wenig and Wez Furlong. That’s worth the price of admission (which was admittedly nothing) right there.
  • Coolest MSFT talk: Martin Maly “Targeting DLR”. I was wholly unaware that the DLR includes an entire compiler back end. Martin summarized the idea of DLR trees on his blog, but the short version is “you parse the language, DLR generates the code”. That’s pretty cool, and should dramatically lower the bar for language development. Of course, I want to write my parser in F#, so I’m going to port the DLR ToyScript sample to F#.
  • Runner-up, Coolest MSFT talk: Erik Meijer “Democratizing the Cloud with Volta”. Erik is a great speaker and he really set the tone of his session with the comment “Division by zero is the goal, not an error”. He was referring to an idea from The Change Function that user’s measure of success is a function of perceived crisis divided by perceived pain of adoption. Erik wants to drive that adoption pain to zero. It’s a laudable goal, but I remain unconvinced on Volta.
  • Coolest Non-MSFT talk: Gilad Bracha “Newspeak”. Newspeak is a new language from one of the co-authors of Java. It’s heavily smalltalk influenced, and runs on Squeak. He showed developing PEGs in Newspeak, and they were very compact and easy to read, easier even than F#. He calls them Executable grammar, and you can read his research paper or review his slides on the topic. Unfortunately, Newspeak isn’t generally available at this time.
  • Runner-up, Coolest Non-MSFT talk: Miguel de Icaza “Moonlight and Mono”. The talk was kinda all-over-the-place, but It’s great to see how far Mono has come. Second Life just started beta testing a Mono-based script runner for their LSL language (apparently, Mono breaks many LSL scripts because it runs them so fast). He also showed off Unity, a 3D game development tool, also running on Mono.
  • Resolver One is a product that bridges the gap between spreadsheets and applications, entirely written in IronPython (around 30,000 lines of app code and 110,000 lines of test code, all in IPy). Creating a spread-sheet based app development environment is one of those ideas that seems obvious in retrospect, at least to me. If you do any kind of complicated spreadsheet based analysis, you should check out their product.
  • If you’re a PowerShell user, you should check out PowerShell+. It’s a free console environment designed for PowerShell and a damn sight better than CMD.exe. If you’re not a PowerShell user, what the heck is wrong with you?
  • Other projects to take a deeper look at: C# Mixins and Cobra Language.
  • I thought my talk went pretty well. It’s was a 15 minute version of my Practical Parsing in F# series. Several folks were surprised I’ve been coding F# for less than a year.

Morning Coffee 140

  • I only posted one Morning Coffee post last week. It wasn’t a lack of content, it was a lack of drive on my part. I had 20-30 items flagged in my news reader, but for some reason I couldn’t work up the interest in posting them. So some of these are a bit old.
  • I’m at the Language.NET Symposium this week, so look for lots of language blogging. I’ve already chatted with Tomáš Petříček and John Lam. If someone kicks Ted Neward’s ass because he hates Perl, I’ll try and liveblog it.
  • Speaking of Ted Neward, he discusses the question “Can Dynamic Languages Scale?” without devolving into a flame-fest. I agree 100% with his point about the difference between performance scaling and complexity scaling. Personally, I tend to err on the side of better complexity scaling, since buying hardware is easier than hiring developers.
  • Nick Malik responds to me calling his shared global integration vision flawed. He points to NGOSS/eTOM as an example of a shared iterative model that works. I know squat about that shared model, so I’ll refrain from commenting until I do a little homework on the telco industry.
  • Speaking of shared interop models, Microsoft is joining DataPortability.org. Dare Obasanjo and Marc Canter are skeptical that so far this effort is all hype and no substance. Reminds me a bit of AttentionTrust.org. But if DataPortability.org can get off the ground, maybe there’s hope for Nick’s vision (or vis-versa).
  • Don Syme lists what’s new in the latest F# release. As I said, this release is pretty light on features. Hopefully, I’ll get some details
  • Tomas Restrepo shows how to change your home folder in PowerShell. I need to do this.