Pretty print a tree

If you want it to be very pretty, you could steal about 25 lines of code from this blog entry to draw it with WPF. But I’ll code up an ascii solution shortly too, probably. EDIT Ok, wow, that was hard. I’m not certain it’s entirely correct, and I can’t help but think there’s probably … Read more

F# if not condition

if you consider that not is also a function, then you can pipe your condition into it to avoid parenthesis like so: if not <| condition param1 param2 then … reason being is if your condition function takes arguments, you don’t need to do not (condition param1 param2) it’s probably a little cleaner to do … Read more

How do I check for reference equality in F#?

The answer, it turns out, is to use LanguagePrimitives.PhysicalEquality: let isSameObject = LanguagePrimitives.PhysicalEquality let a = [1; 2; 3] let b = [1; 2; 3] let a’ = a printfn “%A” (isSameObject a b) // Prints “false” printfn “%A” (isSameObject a a’) // Prints “true” There was precisely one question I could find on Stack … Read more

F# – Should I learn with or without #light?

I’d definitely prefer learning F# with the #light syntax. The non-light version is sometimes useful for understanding some tricks about the F# syntax, but the #light syntax gives you much pleasant experience. For example – using #light let add a b c = let ab = a + b printfn “%d” ab c – ab … Read more

F# Shortcut Syntax for Properties?

F# 3 has auto-implemented properties so you can declare properties without declaring the backing field. Example taken from Properties(F#) on MSDN: type MyClass() = member val MyProperty = “” with get, set

AutoOpen attribute in F#

I think the main use for the AutoOpen attribute is when you want to make some let-bound values available when the user of your library opens a namespace. This is where the attribute is very useful, because I think libraries should generally export all definitions in namespaces, but for some purposes you need to export … Read more

What F# sorcery is this (>=>)?

That’s the Kleisli composition operator for monads. It allows you to compose functions with signatures like ‘a -> M<‘b> and ‘b -> M<‘c’> where M is monadic: in your case the Result<‘t> from the linked article. >=> is really just a function composition, but >> wouldn’t work here since the return type of the first … Read more

When do you put double semicolons in F#?

In the non-interactive F# code that’s not supposed to be compatible with OCaml, you shouldn’t need to ever need double semicolon. In the OCaml compatible mode, you would use it at the end of a top-level function declaration (In the recent versions, you can switch to this mode by using files with .ml extension or … Read more

What’s the easiest way to build an F# compiler that runs on the JVM and generates Java bytecode?

Another option that should probably be considered is to convert the .NET CLR byte code into JVM byte-code like http://www.ikvm.net does with JVM > CLR byte codes. Although this approach has been considered and dismissed by the fjord owner. Getting buy-in from the top with option 1) and have the F# compiler team have pluggable … Read more

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