Namespace aliasing in F#?

F# does not support aliasing of namespaces – only modules and types. So, to resolve the conflicts between .NET assemblies, you will, unfortunatelly, need to define aliases for all the types you’re using.

This may be slightly easier thanks to the fact that F# type aliases are viewed as normal type declarations (by the F# compiler, not by the runtime). This means that, unlike with C# using keyword, you can define them in a spearate file:

// Aliases.fs
namespace SysIO

// Open the 'System' namespace to get a bit shorter syntax
// ('type File = File' is interpreted as discriminated union)
open System

type File = IO.File
type Directory = IO.Directory

In the rest of your application, you can now use SysIO.File. You still have to write the aliases, but at least you don’t have to do that in every file…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)