Take the 2-minute tour ×

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.)

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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.

share|improve this answer
add comment

This works in a fashion similar to extension methods:

module List =
    let doSomething lst v = lst |> List.nth v
share|improve this answer
add comment

Your Answer


