Hey Pedro,
normally you don't have to annotate the type explicitly, since the compiler will infer the type of the empty list from the other branch of the if:

1
2
3
let f () =
    if true then [1]
    else []

However, if you do need it, you can do this:

1
let (k : int list) = []

or

1
2
3
let f () =
    if true then [1]
    else ([] : int list)
By on 6/17/2010 12:04 PM ()

Thanks mau it really worked. However, I was also ending the if then else with a elif, than the compiler was expecting a unit... :P my mistake.

Let me keep working!

(*Just for testing...*)

1
2
3
4
5
6
lif(position.ContainsKey(4)) then

            ([] : Position list)

        else ([] : Position list)
By on 6/17/2010 12:15 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper