views:

91

answers:

2

Quick question. I just read that if you wanted to add a function to e.g. the List module, you can define a new List module with that function:

module List
  let foo = // ...

Does this have the effect of adding foo to the main List module, or do you have to explicitly open the new List? The former seems like Ruby's "monkey patching"; I guess the latter would be more like extension methods.

(I'd try this out but I'm not near a compiler.)

+3  A: 

This works in a fashion similar to extension methods:

module List =
    let doSomething lst v = lst |> List.nth v
ChaosPandion
+2  A: 

It's a lot like namespaces; they're "open". That is, I may have two files or two assemblies that contribute types into a namespace, and then if I use those files or reference those assemblies and say

open ThatNamespace

I see the union of all the members.

Brian