Fork me on GitHub

Code Snippet:

 1 type SeqMonad() =
 2   member t.Bind(m,f) = Seq.concat(Seq.map f m)
 3   member t.Return v = seq{ yield v }
 4 let seqMonad = SeqMonad()
 5 
 6 let permutations ls = 
 7   let rec insertions x = function
 8     | []             -> [[x]]
 9     | (y :: ys) as l -> (x::l)::(List.map (fun x -> y::x) (insertions x ys))
10   let rec permutations' = function
11     | []      -> seq [ [] ]
12     | x :: xs -> Seq.concat (Seq.map (insertions x) (permutations' xs))
13   ls |> permutations'
14 
15 let md5 s =
16   System.BitConverter
17     .ToString(
18       System.Security.Cryptography.MD5
19         .Create()
20         .ComputeHash(buffer = System.Text.Encoding.UTF8.GetBytes(s = s)))
21     .Replace("-", System.String.Empty)
22     .ToLower()
23 
24 let factorial n = 
25   let rec fact acc = function | 0 -> acc | i -> fact (acc * i) (i - 1)
26   (1,n) ||> fact
27 
28 let unitTestPermutations () = 
29   "FooBar" 
30   |> Seq.toList
31   |> fun xs -> xs |> permutations |> Seq.length,
32                xs |> Seq.length   |> factorial
33   |> fun (x,y) -> x = y
34 
35 let unitTestMD5 () =  
36   // [ mon@mbai7 tmp ] md5 -s "FooBar"
37   // MD5 ("FooBar") = f32a26e2a3a8aa338cd77b6e1263c535
38   "FooBar" |> md5 |> fun x -> x = "f32a26e2a3a8aa338cd77b6e1263c535"
39 
40 (unitTestPermutations() && unitTestMD5()) |> function 
41   | true -> () 
42   | false -> failwith "Must be n! permuations per string"
43 
44 let cache file =
45   use reader = System.IO.File.OpenText(file)
46   let rec cache' acc = function
47     | true -> acc
48     | false -> cache' (acc |> Set.add(reader.ReadLine())) reader.EndOfStream
49   cache' Set.empty reader.EndOfStream
50 
51 let root     = __SOURCE_DIRECTORY__
52 let wordList = System.IO.Path.Combine(root,"wordlist.txt")
53 let anagram  = @"poultry outwits ants"
54 let hash     = @"4624d200580677270a54ccff86b9610e"
55 let words    = anagram.Split(char " ")
56 let cached   = wordList |> cache
57 
58 words |> Array.map(fun x  -> x  |> Seq.toList |> permutations)
59       |> Array.map(fun xs -> xs |> Seq.map(fun ys -> ys |> List.map string))
60       |> Array.map(fun xs -> xs |> Seq.map(fun ys -> ys |> List.reduce(+)))
61       |> Array.map(fun xs -> xs |> Seq.filter(fun x -> (x,cached) ||> Set.contains))
62       |> fun xs -> xs.[0],xs.[1],xs.[2]
63       |> fun (xs,ys,zs) -> seqMonad{let! x = xs
64                                     let! y = ys
65                                     let! z = zs
66                                     return (x,y,z)}
67       |> Seq.map(fun (x,y,z) -> x + " " + y + " " + z)
68       |> Seq.map(fun x -> x |> md5, x)
69       |> Seq.filter(fun (x,y) -> x = hash)
70       |> Seq.map(fun (x,y) -> y)
71       |> Seq.truncate 1
72       |> fun x -> x |> printfn "%A"

Code output:

type SeqMonad =
  class
    new : unit -> SeqMonad
    member Bind : m:seq<'b> * f:('b -> #seq<'d>) -> seq<'d>
    member Return : v:'a -> seq<'a>
  end
val seqMonad : SeqMonad
val permutations : ls:'a list -> seq<'a list>
val md5 : s:string -> string
val factorial : n:int -> int
val unitTestPermutations : unit -> bool
val unitTestMD5 : unit -> bool
val cache : file:string -> Set<string>
val root : string = "/Users/mon/tmp"
val wordList : string = "/Users/mon/tmp/wordlist.txt"
val anagram : string = "poultry outwits ants"
val hash : string = "4624d200580677270a54ccff86b9610e"
val words : string [] = [|"poultry"; "outwits"; "ants"|]
val cached : Set<string> =
  set
    ["a"; "a's"; "ab's"; "abaci"; "aback"; "abacus"; "abacus's"; "abacuses";
     "abaft"; ...]

Code result:

> seq []
> val it : unit = ()

References:

Code Snippet:

 1 let bitlength (x:bigint) =
 2   let xs  = x.ToByteArray()
 3   let n   = xs |> Array.length
 4   let msb = xs.[n-1]
 5   let rec bitlength' a = function
 6     | 0uy  -> a
 7     | msb' -> (a+1,msb' >>> 1) ||> bitlength'
 8   ((n-1)*8,msb) ||> bitlength'
 9 
10 let split (x:bigint) m =
11   let y = x >>> m
12   y,(x - (y <<< m))
13 
14 let karatsuba x y =
15   let r = 1 <<< 10
16   let leq x y = (x |> bitlength) <= y
17   let rec karatsuba' = function
18     | (x',y') when (x',r) ||> leq || (y',r) ||> leq -> (x' * y')
19     | (x',y') ->
20       let n = (x' |> bitlength, y' |> bitlength) ||> max
21       let m = n >>> 1
22       let h1,l1 = (x',m) ||> split
23       let h2,l2 = (y',m) ||> split 
24       let z0 = (l1,l2)       |> karatsuba'
25       let z1 = (l1+h1,l2+h2) |> karatsuba'
26       let z2 = (h1,h2)       |> karatsuba'   
27       (z2 <<< (2 * m)) + ((z1 - z0 - z2) <<< m) + z0
28   (x,y) |> karatsuba'
29 
30 let fib n = // tail-recursive with two accs
31   let rec fib' a1 a2 = function
32     | 0 -> 0I
33     | 1 -> a1 + a2
34     | i -> fib' a2 (a1 + a2) (i - 1)
35   fib' 1I 0I n
36 
37 let fibfast n =
38   let inline inner x y i =
39     let a = x * (2I * y - x)
40     let b = y * y + x * x
41     match i % 2 = 0 with | true -> (a,b) | false -> (b, a+b)
42   let rec fibfast' k = function
43     | 0 -> k (0I,1I)
44     | i -> fibfast' (fun (x,y) -> k((x,y,i) |||> inner)) (i >>> 1)
45   (id,n) ||> fibfast' |> fst
46 
47 let fibfastkarat n =
48   let inline inner x y i =
49     let a = (x,((2I,y) ||> karatsuba) - x) ||> karatsuba
50     let b = ((y,y) ||> karatsuba) + ((x,x) ||> karatsuba)
51     match i % 2 = 0 with | true -> (a,b) | false -> (b, a+b)
52   let rec fibfastkarat' k = function
53     | 0 -> k (0I,1I)
54     | i -> fibfastkarat' (fun (x,y) -> k((x,y,i) |||> inner)) (i >>> 1)
55   (id,n) ||> fibfastkarat' |> fst

Code output:

> val bitlength : x:bigint -> int
> val split : x:bigint -> m:int32 -> bigint * System.Numerics.BigInteger
> val karatsuba : x:bigint -> y:bigint -> System.Numerics.BigInteger
> val fib : n:int -> System.Numerics.BigInteger
> val fibfast : n:int -> System.Numerics.BigInteger
> val fibfastkarat : n:int -> System.Numerics.BigInteger

Correctness test:

1 let correctness =
2   ((10. ** 6. |> int |> fib),
3    (10. ** 6. |> int |> fibfast),
4    (10. ** 6. |> int |> fibfastkarat))
5   |> fun (x,y,z) -> x = y && x = z;;

Correctness output:

> val correctness : bool = true

Performance test:

1 let duration f =
2   let t = System.Diagnostics.Stopwatch()
3   t.Start()
4   let x = f()
5   x,t.ElapsedMilliseconds |> float
6 
7 duration(fun _ -> 10. ** 6. |> int |> fib)          |> snd;;
8 duration(fun _ -> 10. ** 6. |> int |> fibfast)      |> snd;;
9 duration(fun _ -> 10. ** 6. |> int |> fibfastkarat) |> snd;;

Performance output:

> val duration : f:(unit -> 'a) -> 'a * float
> val it : float = 198480.0
> val it : float = 4623.0
> val it : float = 1082.0

References:

rename.fsx:

  1 // -------------------------------------------------------------------------------
  2 // Initial rename of library and project script
  3 // -------------------------------------------------------------------------------
  4 
  5 // Bind operator
  6 let (>>=) m f = Option.bind f m
  7 
  8 // Args function that parses command line arguments
  9 let getArg argv key =
 10   let arg = Array.tryFind(fun (a:string) -> a.StartsWith(key)) argv
 11   match arg with
 12   | Some x -> x.Replace(key, "") |> Some
 13   | None -> None
 14 
 15 // Thread-safe console logger
 16 let ts () = System.DateTime.Now.ToString("o")           // ISO-8601
 17 let cw (s:string) = System.Console.WriteLine(s)         // Threadsafe console writer
 18 let cew (s:string) = System.Console.Error.WriteLine(s)  // Threadsafe console error writer
 19 type LogLevel = Info | Warning | Error
 20 let log level x y =
 21   let msg = sprintf "%s - %A: %A (%A)" (ts()) level x y
 22   match level with
 23   | LogLevel.Error -> cew msg
 24   | LogLevel.Info | LogLevel.Warning -> cw msg
 25 
 26 // Generic process executer (needed for "git mv source target")
 27 let executeProcess exe args dir =
 28   try
 29     let psi = new System.Diagnostics.ProcessStartInfo(exe,args) 
 30     psi.CreateNoWindow <- true        
 31     psi.UseShellExecute <- false
 32     psi.RedirectStandardOutput <- true
 33     psi.RedirectStandardError <- true
 34     psi.WorkingDirectory <- dir
 35     let p = System.Diagnostics.Process.Start(psi)
 36     let o = new System.Text.StringBuilder()
 37     let e = new System.Text.StringBuilder()
 38     p.OutputDataReceived.Add(fun x -> o.AppendLine(x.Data) |> ignore)
 39     p.ErrorDataReceived.Add(fun x -> e.AppendLine(x.Data) |> ignore)
 40     p.BeginErrorReadLine()
 41     p.BeginOutputReadLine()
 42     p.WaitForExit()
 43     (p.ExitCode, o.ToString(), e.ToString()) |> Some
 44   with ex -> log LogLevel.Error (exe,args,dir) ex; None
 45 
 46 // Scaffold & Template
 47 let scaffold = "FSharp.ProjectScaffold"
 48 let template = "FSharp.ProjectTemplate"
 49 
 50 // The name of the library (will replace "FSharp.ProjectScaffold")
 51 let lib = 
 52   ((fsi.CommandLineArgs,"lib=") ||> getArg, "FSharp.Foo")
 53   ||> defaultArg
 54 
 55 // The name of the project (will replace "FSharp.ProjectTemplate")
 56 let proj =
 57   ((fsi.CommandLineArgs,"proj=") ||> getArg, "FSharp.Bar")
 58   ||> defaultArg
 59 
 60 // Folder & file helper functions
 61 let root = __SOURCE_DIRECTORY__
 62 let recursively = System.IO.SearchOption.AllDirectories
 63 let pattern filter = "*" + filter + "*"
 64 let pattern' filter = "*" + filter
 65 let dirs path filter =
 66   System.IO.Directory.EnumerateDirectories(path,filter,recursively)
 67 let files path filter =
 68   System.IO.Directory.EnumerateFiles(path,filter,recursively)
 69 let rev (s:string) =
 70   s |> Seq.toArray |> Array.fold(fun a x -> (x |> string) + a) ""
 71 let replaceFirst input from to' =
 72   let r = new System.Text.RegularExpressions.Regex(from)
 73   r.Replace(input = input,replacement = to', count = 1)
 74 let isGit =
 75   let exe  = "git"
 76   let args = sprintf "status"
 77   let git  = (exe,args,root) |||> executeProcess
 78   git |> function | Some (x,y,z) -> x = 0 | None -> false
 79 let renameGit path path' =
 80   let exe  = "git"
 81   let args = sprintf "mv \"%s\" \"%s\"" path path'
 82   (exe,args,root) |||> executeProcess, path, path'
 83 let renameDirs path path' =
 84   System.IO.Directory.Move(path,path') |> ignore
 85   (0,"","") |> Some,path,path'
 86 let renameFiles path path' =
 87   System.IO.File.Move(path,path') |> ignore
 88   (0,"","") |> Some,path,path'
 89 let rename' path path' =
 90   match isGit with
 91   | true -> (path,path') ||> renameGit
 92   | false ->
 93     match System.IO.File.GetAttributes(path) with
 94     | System.IO.FileAttributes.Directory -> (path,path') ||> renameDirs 
 95     | _ -> (path,path') ||> renameFiles
 96 let rename (path:string) from to' =
 97   let from' = from  |> rev
 98   let to''  = to'   |> rev
 99   let path' = (path |> rev, from', to'') |||> replaceFirst |> rev
100   (path,path') ||> rename'
101 let rollback xs = xs |> List.iter(fun (x,y) -> (y,x) ||> rename' |> ignore)
102 
103 // File content helper functions
104 let utf8 = System.Text.UTF8Encoding.UTF8
105 let readLines path = System.IO.File.ReadLines(path,utf8)
106 let writeLines path (contents:string seq)  =
107   System.IO.File.WriteAllLines(path,contents,utf8)
108 let copy from to' =
109   System.IO.File.Copy(from,to',true)
110 let delete path = System.IO.File.Delete(path)
111 let extensions = [ ".sln"; ".fs"; ".fsx"; ".fsproj"; ".nuspec"; ".md" ]
112 
113 // Rename files or directories
114 let renameIO from to' fn atomic' =
115   try
116       (root,from |> pattern) ||> fn
117       |> Seq.map(fun x -> (x,from,to') |||> rename)
118       |> Seq.fold(fun (i,acc) (x,y,z) ->
119                   let i' =
120                     match x with
121                     | Some (a,b,c) -> a
122                     | None -> 1
123                   (i+i',(y,z)::acc)) (0,[])
124       |> fun (x,y) ->
125         match x with
126         | 0 -> (y,atomic') ||> List.append |> Some
127         | _ -> atomic' |> rollback; None
128   with ex -> log LogLevel.Error (atomic',from,to') ex; None
129 
130 // Update files content
131 let updateContent exts atomic' =
132   try
133     exts
134     |> Seq.map(fun x -> (root,x |> pattern') ||> files)
135     |> Seq.fold(fun a x -> (x,a) ||> Seq.append) Seq.empty
136     |> Seq.filter(fun x -> not (x.Contains "rename.fsx"))
137     |> Seq.fold(fun a x ->
138                 let x' = x + "_"
139                 x |> readLines
140                   |> Seq.map(fun y -> y.Replace(scaffold,lib)
141                                        .Replace(template,proj))
142                   |> writeLines x'
143                 (x,x')::a) []
144     |> Seq.iter(fun (x,y) -> (y,x) ||> copy; y |> delete)
145     |> Some
146   with ex ->
147     let git =
148       match isGit with
149       | false -> (0,"","") |> Some // Not really rollback but ...
150       | true ->
151         let exe  = "git"
152         let args = sprintf "checkout -- *"
153         (exe,args,root) |||> executeProcess
154     atomic' |> rollback
155     log LogLevel.Error (exts,git) ex; None
156 
157 // Rename with atomicity "git mv file2 file1"
158 [] |> Some >>= (renameIO scaffold lib dirs)
159            >>= (renameIO template proj dirs)
160            >>= (renameIO scaffold lib files)
161            >>= (renameIO template proj files)
162 
163 // Update content
164            >>= (updateContent extensions)

rename.cmd:

@echo off
:: Add the paths for the F# SDK 3.x (from higher version to lower)
set FSHARPSDK=^
C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\;^
C:\Program Files (x86)\Microsoft SDKs\F#\3.0\Framework\v4.0\

cls
:: Execute the script "only" with the first "fsianycpu.exe" found
for %%i in (fsianycpu.exe) do "%%~$FSHARPSDK:i" rename.fsx %*

pause

rename.sh:

#!/bin/bash
#workaround to handle different path for fsi
export FSHARPI=`which fsharpi`
cat - > fsharpi <<"EOF"
#!/bin/bash
$FSHARPI $@
EOF
chmod +x fsharpi
fsharpi rename.fsx $@
rm fsharpi

Git clone FSharp.ProjectScaffold

[ mon@mbai7 rename ] git clone git@github.com:fsprojects/FSharp.ProjectScaffold.git
Cloning into 'FSharp.ProjectScaffold'...
remote: Reusing existing pack: 674, done.
remote: Total 674 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (674/674), 593.40 KiB | 375.00 KiB/s, done.
Resolving deltas: 100% (342/342), done.
Checking connectivity... done.
[ mon@mbai7 rename ] cd FSharp.ProjectScaffold/

Grep for FSharp.ProjectScaffold and FSharp.ProjectTemplate:

[ mon@mbai7 FSharp.ProjectScaffold ] grep -R "FSharp.ProjectScaffold" .
./build.fsx:let solutionFile  = "FSharp.ProjectScaffold"
./build.fsx:let gitName = "FSharp.ProjectScaffold"
./docs/content/index.fsx:  [content]: https://github.com/fsprojects/FSharp.ProjectScaffold/tree/master/docs/content
./docs/content/index.fsx:  [gh]: https://github.com/fsprojects/FSharp.ProjectScaffold
./docs/content/index.fsx:  [issues]: https://github.com/fsprojects/FSharp.ProjectScaffold/issues
./docs/content/index.fsx:  [readme]: https://github.com/fsprojects/FSharp.ProjectScaffold/blob/master/README.md
./docs/content/index.fsx:  [license]: https://github.com/fsprojects/FSharp.ProjectScaffold/blob/master/LICENSE.txt
./docs/tools/generate.fsx:let website = "/FSharp.ProjectScaffold"
./docs/tools/generate.fsx:let githubLink = "http://github.com/fsprojects/FSharp.ProjectScaffold"
./docs/tools/generate.fsx:  [ "project-name", "FSharp.ProjectScaffold"
./docs/tools/generate.fsx:    "project-nuget", "http://nuget.com/packages/FSharp.ProjectScaffold" ]
./nuget/FSharp.ProjectTemplate.nuspec:    <licenseUrl>http://github.com/fsprojects/FSharp.ProjectScaffold/blob/master/LICENSE.txt</licenseUrl>
./nuget/FSharp.ProjectTemplate.nuspec:    <projectUrl>http://fsprojects.github.com/FSharp.ProjectScaffold</projectUrl>
./nuget/FSharp.ProjectTemplate.nuspec:    <iconUrl>https://raw.github.com/fsharp/FSharp.ProjectScaffold/master/nuget/logo.png</iconUrl>
./README.md:FSharp.ProjectScaffold
./README.md:      <td><a href="FSharp.ProjectScaffold.sln">FSharp.ProjectScaffold.sln</a></td>
./README.md:<a href="http://fsprojects.github.io/FSharp.ProjectScaffold" target="_blank">Sample API documents available here.</a>
./RELEASE_NOTES.md:* Changed name from fsharp-project-scaffold to FSharp.ProjectScaffold
./rename.fsx:let scaffold = "FSharp.ProjectScaffold"
./rename.fsx:// The name of the library (will replace "FSharp.ProjectScaffold")
./tests/FSharp.ProjectTemplate.Tests/Tests.fs:module FSharp.ProjectScaffold.Tests
[ mon@mbai7 FSharp.ProjectScaffold ] grep -R "FSharp.ProjectTemplate" .
./build.fsx:let project = "FSharp.ProjectTemplate"
./docs/content/index.fsx:      The F# ProjectTemplate library can be <a href="https://nuget.org/packages/FSharp.ProjectTemplate">installed from NuGet</a>:
./docs/content/index.fsx:      <pre>PM> Install-Package FSharp.ProjectTemplate</pre>
./docs/content/index.fsx:#r "FSharp.ProjectTemplate.dll"
./docs/content/index.fsx:open FSharp.ProjectTemplate
./docs/content/tutorial.fsx:#r "FSharp.ProjectTemplate.dll"
./docs/content/tutorial.fsx:open FSharp.ProjectTemplate
./docs/tools/generate.fsx:let referenceBinaries = [ "FSharp.ProjectTemplate.dll" ]
./FSharp.ProjectScaffold.sln:Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.ProjectTemplate", "src\FSharp.ProjectTemplate\FSharp.ProjectTemplate.fsproj", "{7E90D6CE-A10B-4858-A5BC-41DF7250CBCA}"
./FSharp.ProjectScaffold.sln:																									 	 nuget\FSharp.ProjectTemplate.nuspec = nuget\FSharp.ProjectTemplate.nuspec
./FSharp.ProjectScaffold.sln:Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.ProjectTemplate.Tests", "tests\FSharp.ProjectTemplate.Tests\FSharp.ProjectTemplate.Tests.fsproj", "{E789C72A-5CFD-436B-8EF1-61AA2852A89F}"
./nuget/FSharp.ProjectTemplate.nuspec:    <file src="..\bin\FSharp.ProjectTemplate.dll" target="lib/net40" />
./README.md:        A good way to get started is to rename the project included in this sample (FSharp.ProjectTemplate). 
./rename.fsx:let template = "FSharp.ProjectTemplate"
./rename.fsx:// The name of the project (will replace "FSharp.ProjectTemplate")
./src/FSharp.ProjectTemplate/AssemblyInfo.fs:[<assembly: AssemblyTitleAttribute("FSharp.ProjectTemplate")>]
./src/FSharp.ProjectTemplate/AssemblyInfo.fs:[<assembly: AssemblyProductAttribute("FSharp.ProjectTemplate")>]
./src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj:    <RootNamespace>FSharp.ProjectTemplate</RootNamespace>
./src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj:    <AssemblyName>FSharp.ProjectTemplate</AssemblyName>
./src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj:    <Name>FSharp.ProjectTemplate</Name>
./src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj:    <DocumentationFile>bin\Debug\FSharp.ProjectTemplate.xml</DocumentationFile>
./src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj:    <DocumentationFile>..\..\bin\FSharp.ProjectTemplate.xml</DocumentationFile>
./src/FSharp.ProjectTemplate/Library.fs:namespace FSharp.ProjectTemplate
./src/FSharp.ProjectTemplate/Script.fsx:open FSharp.ProjectTemplate
./tests/FSharp.ProjectTemplate.Tests/FSharp.ProjectTemplate.Tests.fsproj:    <RootNamespace>FSharp.ProjectTemplate.Tests</RootNamespace>
./tests/FSharp.ProjectTemplate.Tests/FSharp.ProjectTemplate.Tests.fsproj:    <AssemblyName>FSharp.ProjectTemplate.Tests</AssemblyName>
./tests/FSharp.ProjectTemplate.Tests/FSharp.ProjectTemplate.Tests.fsproj:    <Name>FSharp.ProjectTemplate.Tests</Name>
./tests/FSharp.ProjectTemplate.Tests/FSharp.ProjectTemplate.Tests.fsproj:    <DocumentationFile>bin\Release\FSharp.ProjectTemplate.Tests.xml</DocumentationFile>
./tests/FSharp.ProjectTemplate.Tests/FSharp.ProjectTemplate.Tests.fsproj:    <ProjectReference Include="..\..\src\FSharp.ProjectTemplate\FSharp.ProjectTemplate.fsproj">
./tests/FSharp.ProjectTemplate.Tests/FSharp.ProjectTemplate.Tests.fsproj:      <Name>FSharp.ProjectTemplate</Name>
./tests/FSharp.ProjectTemplate.Tests/Tests.fs:open FSharp.ProjectTemplate

Rename FSharp.ProjectScaffold and FSharp.ProjectTemplate:

[ mon@mbai7 FSharp.ProjectScaffold ] cp ../rename.* .
‘../rename.cmd’ -> ‘./rename.cmd’
‘../rename.fsx’ -> ‘./rename.fsx’
‘../rename.sh’ -> ‘./rename.sh’
[ mon@mbai7 FSharp.ProjectScaffold ] chmod +x rename.sh 
[ mon@mbai7 FSharp.ProjectScaffold ] ./rename.sh lib=Stermon.Foo proj=Stermon.Bar

Grep for FSharp.ProjectScaffold and FSharp.ProjectTemplate (again):

[ mon@mbai7 FSharp.ProjectScaffold ] grep -R "FSharp.ProjectScaffold" .
./rename.fsx:let scaffold = "FSharp.ProjectScaffold"
./rename.fsx:// The name of the library (will replace "FSharp.ProjectScaffold")
[ mon@mbai7 FSharp.ProjectScaffold ] grep -R "FSharp.ProjectTemplate" .
./rename.fsx:let template = "FSharp.ProjectTemplate"
./rename.fsx:// The name of the project (will replace "FSharp.ProjectTemplate")

Build FSharp.ProjectScaffold:

[ mon@mbai7 FSharp.ProjectScaffold ] chmod +x build.sh 
[ mon@mbai7 FSharp.ProjectScaffold ] ./build.sh 
Installing 'FAKE 2.15.2'.
Successfully installed 'FAKE 2.15.2'.
fsharpi build.fsx
Building project with version: LocalBuild
Shortened DependencyGraph for Target All:
<== All
<== RunTests
<== Build
<== AssemblyInfo
<== RestorePackages
      <== Clean

The resulting target order is:
 - Clean
 - RestorePackages
 - AssemblyInfo
 - Build
 - RunTests
 - All
Starting Target: All (==> RunTests)
Starting Target: RunTests (==> Build)
Starting Target: Build (==> AssemblyInfo)
Starting Target: AssemblyInfo (==> RestorePackages)
Starting Target: RestorePackages (==> Clean)
Starting Target: Clean 
Deleting contents of bin
Deleting contents of temp
Finished Target: Clean

...

Execution Runtime: mono-3.5
***** Stermon.Foo.Tests.hello returns 42
42

Tests run: 1, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.0387905 seconds
  Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0

Finished Target: RunTests
Finished Target: All
Killing all processes that are created by FAKE and are still running.

---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target            Duration
------            --------
Clean             00:00:00.0043722
RestorePackages   00:00:02.4633336
AssemblyInfo      00:00:00.0062624
Build             00:00:05.3281672
RunTests          00:00:01.1349369
All               00:00:00.0000441
Total:            00:00:08.9734871
Status:           Ok
---------------------------------------------------------------------

Stermon.Foo and Stermon.Bar:

[ mon@mbai7 FSharp.ProjectScaffold ] ll . bin/ src/ tests/
.:
total 64K
-rw-r--r--  1 mon staff 1.2K Apr 25 18:20 LICENSE.txt
-rw-r--r--  1 mon staff  16K Apr 25 18:45 README.md
-rw-r--r--  1 mon staff  374 Apr 25 18:45 RELEASE_NOTES.md
-rw-r--r--  1 mon staff 3.2K Apr 25 18:45 Stermon.Foo.sln
-rw-r--r--  1 mon staff 1.7K Apr 25 18:48 TestResults.xml
drwxr-xr-x  5 mon staff  170 Apr 25 18:48 bin/
-rw-r--r--  1 mon staff  182 Apr 25 18:20 build.cmd
-rw-r--r--  1 mon staff 5.6K Apr 25 18:45 build.fsx
-rwxr-xr-x  1 mon staff  398 Apr 25 18:20 build.sh*
drwxr-xr-x  6 mon staff  204 Apr 25 18:20 docs/
drwxr-xr-x  3 mon staff  102 Apr 25 18:45 lib/
drwxr-xr-x  5 mon staff  170 Apr 25 18:45 nuget/
drwxr-xr-x 10 mon staff  340 Apr 25 18:48 packages/
-rw-r--r--  1 mon staff   39 Apr 25 18:44 rename.cmd
-rw-r--r--  1 mon staff 5.2K Apr 25 18:44 rename.fsx
-rwxr-xr-x  1 mon staff   59 Apr 25 18:44 rename.sh*
drwxr-xr-x  3 mon staff  102 Apr 25 18:41 src/
drwxr-xr-x  2 mon staff   68 Apr 25 18:48 temp/
drwxr-xr-x  3 mon staff  102 Apr 25 18:41 tests/

bin/:
total 12K
-rwxr-xr-x 1 mon staff 4.0K Apr 25 18:48 Stermon.Bar.dll*
-rw-r--r-- 1 mon staff  276 Apr 25 18:48 Stermon.Bar.dll.mdb
-rw-r--r-- 1 mon staff  196 Apr 25 18:48 Stermon.Bar.xml

src/:
total 0
drwxr-xr-x 7 mon staff 238 Apr 25 18:48 Stermon.Bar/

tests/:
total 0
drwxr-xr-x 7 mon staff 238 Apr 25 18:48 Stermon.Bar.Tests/

Git status:

[ mon@mbai7 FSharp.ProjectScaffold ] git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	renamed:    FSharp.ProjectScaffold.sln -> Stermon.Foo.sln
	renamed:    nuget/FSharp.ProjectTemplate.nuspec -> nuget/Stermon.Bar.nuspec
	renamed:    src/FSharp.ProjectTemplate/AssemblyInfo.fs -> src/Stermon.Bar/AssemblyInfo.fs
	renamed:    src/FSharp.ProjectTemplate/Library.fs -> src/Stermon.Bar/Library.fs
	renamed:    src/FSharp.ProjectTemplate/Script.fsx -> src/Stermon.Bar/Script.fsx
	renamed:    src/FSharp.ProjectTemplate/FSharp.ProjectTemplate.fsproj -> src/Stermon.Bar/Stermon.Bar.fsproj
	renamed:    tests/FSharp.ProjectTemplate.Tests/FSharp.ProjectTemplate.Tests.fsproj -> tests/Stermon.Bar.Tests/Stermon.Bar.Tests.fsproj
	renamed:    tests/FSharp.ProjectTemplate.Tests/Tests.fs -> tests/Stermon.Bar.Tests/Tests.fs
	renamed:    tests/FSharp.ProjectTemplate.Tests/packages.config -> tests/Stermon.Bar.Tests/packages.config

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   README.md
	modified:   RELEASE_NOTES.md
	modified:   Stermon.Foo.sln
	deleted:    bin/README.md
	modified:   build.fsx
	modified:   build.sh
	modified:   docs/content/index.fsx
	modified:   docs/content/tutorial.fsx
	modified:   docs/output/README.md
	modified:   docs/tools/generate.fsx
	modified:   lib/README.md
	modified:   nuget/README.md
	modified:   nuget/Stermon.Bar.nuspec
	modified:   packages/README.md
	modified:   src/Stermon.Bar/AssemblyInfo.fs
	modified:   src/Stermon.Bar/Library.fs
	modified:   src/Stermon.Bar/Script.fsx
	modified:   src/Stermon.Bar/Stermon.Bar.fsproj
	deleted:    temp/README.md
	modified:   tests/Stermon.Bar.Tests/Stermon.Bar.Tests.fsproj
	modified:   tests/Stermon.Bar.Tests/Tests.fs

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	rename.cmd
	rename.fsx
	rename.sh

References: