Overload resolution in Phalanger

PHP language itself doesn't method support overloading (having two methods with same name, but different number or types of parameters). This brings an interesting problem to Phalanger, because most of .NET languages support this and if we want to be able to call any .NET object from PHP we need to add support (at least) for calling of overloaded methods. The latest Phalanger release contains overload resolution described in the Integrating PHP with CLR document [1].

For example, when calling the Console::WriteLine method (which has a lot of overloads), Phalanger dynamically generates a piece of code that we call dynamic stub, which is responsible for choosing the most appropriate overload depending on the actual parameter types. This stub is generated only once for every method, which makes this implementation very efficient. The difficult part of overload resolution is, how can the stub determine what is the best overload? PHP language has a lot of implicit conversions, so when you pass the string "10.2 Little Piggies" to a method it can be implicitly converted to float (10.2) (For more details see [2]). Another example of implicit conversion is that any boolean value can be converted to string (empty string or string "0" are converted to false, every other string is converted to true).

In this article I'll describe how does the dynamic stub look like in current version of Phalanger, what problems can it cause and how are we going to fix it in the future version!

Published: Thursday, 15 February 2007, 9:46 PM
Tags: phalanger
Read the complete article

Quotations Visualizer for F#

Quotation Visualizer is my tool that shows visual representation of F# quotations. Stephen noticed (Thanks!) that Quotation Visualizer doesn't compile with the latest version of F# (, so here is the updated version:

If you want to know more about this tool, here are links to previous articles about it:

What was wrong?

This tool is written using F# light syntax, which means that you don't have to write all the semicolons and F# compiler uses whitespace to determine end of the blocks (and some other constructs). This compiler option is relatively new so it is still evolving. First issue that I had is with class declaration - the following code is not valid with the latest F# version:

type MyForm = class inherit Form as base
  // ...

I used it because it looks more familiar to C# developers :-). Instead of it you have to write the following:

type MyForm = class 
  inherit Form as base
  // ...

The second issue was with the pipeline operator which is useful when working with lists (or other sequences). The correct syntax for using pipeline operator (for expressions that are longer than one line) is following:

let filteredList = 
    |> Array.to_list 
    |> ( fun m -> /* ... */ ) 
    |> List.filter ( fun m -> /* ... */ ) 

Published: Wednesday, 14 February 2007, 11:35 PM
Tags: f#
Read the complete article

Compiling Texy! with Phalanger

Texy! [1] is a convertor from text format (similar to formats used in some wiki applications) to valid XHTML code written in PHP. The syntax is described at Texy! web page [2]. Unfortunately, it is only in Czech language, but the syntax is very straightforward, so you can understand it without learning Czech :-).

In this article, we'll examine how to compile Texy! using Phalanger in pure mode. In this mode it is possible to use objects from PHP like any other .NET objects, so we can later used the compiled assembly for example in the following C# code:

// Create instance of Texy! parser
Texy t = new Texy();
// Call the 'process' method and cast result to string
string parsed = (string)t.process(txtTexy.Text);
// Display parsed text using literal
ltrOutput.Text = parsed;

Published: Monday, 12 February 2007, 12:45 AM
Tags: phalanger
Read the complete article

All blog posts by tag

f# (112), functional (66), research (48), c# (37), asynchronous (27), academic (26), parallel (23), programming languages (21), functional programming (20), universe (20), meta-programming (18), philosophy (16), links (15), presentations (14), data science (12), writing (12), joinads (12), web (11), thegamma (11), talks (9), data journalism (9), math and numerics (9), random thoughts (9), phalanger (8), haskell (7), mono (7), webcast (7), design (5), fslab (5), open source (5), architecture (4), visualization (4), fun (4), accelerator (4), type providers (3), linq (3), f# data (3), .net (3), training (2), coeffects (2), deedle (2), monads (2), art (2), fractals (2), funscript (2), new york (2), manning (2), books (2)