Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split F# modules across multiple files

Tags:

.net

module

f#

Is it possible to split an F# module across files?

According to the book I have it is, but the book is probably outdated (Foundations of F#)

like image 356
TimothyP Avatar asked Apr 27 '09 13:04

TimothyP


People also ask

What is split () in Python?

The split() method splits a string into a list. You can specify the separator, default separator is any whitespace. Note: When maxsplit is specified, the list will contain the specified number of elements plus one.

What does split do in PySpark?

The PySpark SQL provides the split() function to convert delimiter separated String to an Array (StringType to ArrayType) column on DataFrame It can be done by splitting the string column on the delimiter like space, comma, pipe, etc. and converting it into ArrayType.

How do you split a string?

The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.

How do you split a word in Python?

Python String split() Method A string can be split into substrings using the split(param) method. This method is part of the string object. The parameter is optional, but you can split on a specific string or character. Given a sentence, the string can be split into words.


2 Answers

Apparently not:

C:\temp\Tim>type 1.fs 2.fs  1.fs   #light module Module  let sayHello1 = printfn "Hello, "  2.fs   #light module Module  let sayHello2 = printfn "world!"  C:\temp\Tim>fsc 1.fs 2.fs Microsoft F# Compiler, (c) Microsoft Corporation, All Rights Reserved F# Version 1.9.6.2, compiling for .NET Framework Version v2.0.50727  2.fs(2,1): error FS0191: An implementation of the file or module Module has already been given. 

Update: the error has changed in F# 4.0, it is now:

error FS0248: Two modules named 'Module' occur in two parts of this assembly

where Module is the fully qualified name of your assembly, including the namespace part.

like image 135
Tim Robinson Avatar answered Sep 20 '22 12:09

Tim Robinson


The type extensions are cool, and hopefully they will allow to be cross file, while still being intrinsic. If you do a type extension in the same file, it compiles to one class, and the extension has access to private members and so on. If you do it in another file, it's just an "optional" extension, like C# static extension methods. (Even though the F# specs say differently.)

I'd be surprised if this isn't addressed at some point, if only for designer support. If intrinsic type extensions could be anywhere in the assembly, that'd be pretty slick.

Another option, which might not be what you want, is to create a type and a module, call the module the same name, and then add the ModuleSuffix flag to it:

type Foo() =      static member Bar = 1  [<CompilationRepresentationAttribute(CompilationRepresentationFlags.ModuleSuffix)>] module Foo =     let Baz = 2  printfn "%d %d" Foo.Bar Foo.Baz 

This is used in the F# libraries, so they can have a type List or whatever, along with tons of helper stuff in a module.

like image 27
MichaelGG Avatar answered Sep 21 '22 12:09

MichaelGG