You can't do exactly what you want but there are a couple of alteratives that come close. Open statements only apply to the current module so you could create lots of small modules to reduce the scope of your open statements:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// compiles
module Foo =
    open LazyList
    // return llist holding all the leading elements of l that satisfy the test f
    let llist_takef f l =
        let unf l =
            match l with
            | Cons(h, t) when f h ->
                Some(h, t)
            | _ -> None
        unfold unf l
    
// doesn't compile - LazyList no longer open
// return llist holding all the leading elements of l that satisfy the test f
let llist_takef f l =
    let unf l =
        match l with
        | Cons(h, t) when f h ->
            Some(h, t)
        | _ ->
            None
    unfold unf l

Alteratively you can use the module keyword to give a shorter alias to a module:

1
2
3
4
5
6
7
8
9
10
11
module LL = LazyList

// return llist holding all the leading elements of l that satisfy the test f
let llist_takef f l =
    let unf l =
        match l with
        | LL.Cons(h, t) when f h ->
            Some(h, t)
        | _ ->
            None
    LL.unfold unf l

This would be my perfered solution as it saves typing out long module names, but still allows you to easily see where the values/functions are coming from.

By on 10/24/2007 6:29 AM ()
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