error FS0039: The type <sometype> is not defined

error FS0039: The type <sometype> is not defined

Although my project compiles just file I can't get scripts to execute within Visual Studio in F# Interactive mode. I keep getting errors like "error FS0039: The type <sometype> is not defined." Here is an EXTREMELY simple repro scenario:

the first file is called Units.fs

namespace FSharpTest

[<Measure>] type rad // angle, radians
[<Measure>] type deg // angle, angle


the second file is called Trig.fs

namespace FSharpTest

module Trig =
    let radInCircle = 2.0 * 3.1415 * 1.0<rad>


and my script file, which does nothing right now, is called Script.fsx

#load "Units.fs"
#load "Trig.fs"


when I try to send this script to Interactive, I get the error "Trig.fs(4,42): error FS0039: The type 'rad' is not defined". The only way I've been able to get around this is to follow every #load in my script with "open FSharpTest". so if I've got 10 .fs files, then my script would have 10 "open FSharpTest" lines. this is really kind of ugly and i can't believe other people are actually doing this. some other people have had this problem - see stackoverflow and i wonder what is an elegant solution to this problem. and why doesn't it work the way i'd expect?
I think this is an enhancement request.

Each script file loaded is being compiled into a separate dynamic assembly, so that sets some encapsulation barriers between files that are the root of the problem.

I've not had any success with the [<AutoOpen>] attribute as either a module or assembly annotation -- the only thing that seems to work other than the interleaved open statements in the combining .fsx file is to make each separate file open its own namespace too, perhaps guarded for interactive use only like


namespace FSharpTest
#if INTERACTIVE
open FSharpTest
#endif

module Trig =
    let radInCircle = 2.0 * 3.1415 * 1.0<rad>

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright