Skip to content

Commit

Permalink
Fix error in literate script and add some test
Browse files Browse the repository at this point in the history
  • Loading branch information
tpetricek committed Dec 27, 2012
1 parent 9dd77ed commit db21b8f
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 2 deletions.
6 changes: 4 additions & 2 deletions literate/literate.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ and `FSharp.CodeFormat.dll` to colorize F# source & parse Markdown:

(*** hide ***)
namespace FSharp.Literate

#if INTERACTIVE
// #I "../bin/"
#r "System.Web.dll"
#r "FSharp.Markdown.dll"
#r "FSharp.CodeFormat.dll"
#load "StringParsing.fs"
#endif

open System
open System.IO
Expand Down Expand Up @@ -493,7 +495,7 @@ module internal SourceProcessors =
// Process all paragraphs in two steps (replace F# snippets & references)
let paragraphs =
doc.Paragraphs |> List.choose (fun par ->
par |> replaceCodeSnippets Map.empty
par |> replaceCodeSnippets codeLookup
|> Option.bind (replaceReferences refLookup))

// Construct new Markdown document and write it
Expand Down
9 changes: 9 additions & 0 deletions src/FSharp.Formatting.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documentation", "Documentat
..\docs\markdown.fsx = ..\docs\markdown.fsx
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Literate.Tests", "FSharp.Literate.Tests\FSharp.Literate.Tests.fsproj", "{C22A18AB-6C54-48B4-AAC5-892499E93D4D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -63,6 +65,13 @@ Global
{5DEBD769-D86E-4E14-ABF1-373CA91BFAA2}.Release|Any CPU.Build.0 = Release|Any CPU
{5DEBD769-D86E-4E14-ABF1-373CA91BFAA2}.Release|x86.ActiveCfg = Release|x86
{5DEBD769-D86E-4E14-ABF1-373CA91BFAA2}.Release|x86.Build.0 = Release|x86
{C22A18AB-6C54-48B4-AAC5-892499E93D4D}.Debug|Any CPU.ActiveCfg = Debug|x86
{C22A18AB-6C54-48B4-AAC5-892499E93D4D}.Debug|Any CPU.Build.0 = Debug|x86
{C22A18AB-6C54-48B4-AAC5-892499E93D4D}.Debug|x86.ActiveCfg = Debug|x86
{C22A18AB-6C54-48B4-AAC5-892499E93D4D}.Debug|x86.Build.0 = Debug|x86
{C22A18AB-6C54-48B4-AAC5-892499E93D4D}.Release|Any CPU.ActiveCfg = Release|x86
{C22A18AB-6C54-48B4-AAC5-892499E93D4D}.Release|x86.ActiveCfg = Release|x86
{C22A18AB-6C54-48B4-AAC5-892499E93D4D}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 6 additions & 0 deletions src/FSharp.Literate.Tests/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
85 changes: 85 additions & 0 deletions src/FSharp.Literate.Tests/FSharp.Literate.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{c22a18ab-6c54-48b4-aac5-892499e93d4d}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>FSharp.Literate.Tests</RootNamespace>
<AssemblyName>FSharp.Literate.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<Name>FSharp.Literate.Tests</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;TEST</DefineConstants>
<WarningLevel>3</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\Debug\FSharp.Literate.Tests.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<DocumentationFile>bin\Release\FSharp.Literate.Tests.XML</DocumentationFile>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets" Condition="!Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
<ItemGroup>
<Compile Include="../../literate/StringParsing.fs">
<Link>StringParsing.fs</Link>
</Compile>
<Compile Include="../../literate/literate.fsx">
<Link>Literate.fsx</Link>
</Compile>
<Compile Include="Program.fs" />
<None Include="App.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="test.md">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="template-file.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FSharp.CodeFormat\FSharp.CodeFormat.fsproj">
<Name>FSharp.CodeFormat</Name>
<Project>{341ebf32-d470-4c55-99e9-55f14f7ffbb1}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\FSharp.Markdown\FSharp.Markdown.fsproj">
<Name>FSharp.Markdown</Name>
<Project>{c44c1c05-599a-40dd-9590-465eab8960c5}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
12 changes: 12 additions & 0 deletions src/FSharp.Literate.Tests/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
open System.IO
open System.Reflection
open FSharp.Literate

[<EntryPoint>]
let main argv =
let asmCompiler = Assembly.LoadFile(@"C:\Program Files (x86)\Microsoft F#\v4.0\FSharp.Compiler.dll")
let loc = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
let source = Path.Combine(loc, "test.md")
let template = Path.Combine(loc, "template-file.html")
Literate.ProcessMarkdown(source, template, fsharpCompiler=asmCompiler)
0
35 changes: 35 additions & 0 deletions src/FSharp.Literate.Tests/template-file.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--
The {page-title} parameters will be replaced with the
document title extracted from the <h1> element or
file name, if there is no <h1> heading
-->
<title>{page-title}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://code.jquery.com/jquery-1.8.0.js"></script>
<script src="http://code.jquery.com/ui/1.8.23/jquery-ui.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="content/style.css" />
<script src="content/tips.js" type="text/javascript"></script>
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="row" style="margin-top:30px">
<div class="span1"></div>
<div class="span10" id="main">
{document}
{tooltips}
</div>
<div class="span1"></div>
</div>
</div>
</body>
</html>
49 changes: 49 additions & 0 deletions src/FSharp.Literate.Tests/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Dynamic programming
===================================


Dynamic programming is equivalent to the folowwing two concepts used together : _recursion_ and _deforestation_


Recursion
---------

Recursion allows to _express_ solutions that bends itself to it in a simpler way. It is merely a way to formulate a solution in terms of a **subproblem graph** of diminishing size. by itself, it does not reduce the complexity of computing the solution.



Deforestation
-------------


If subproblems appears multiple times in the subproblem graph, then storing intermediary results allows for a dynamic folding of it, replacing the graph with its computed value. This is where the improvement of the dynamic programming comes from.


Two strategies are possible for this :

- a **bottom up** approach, evaluating adjacents sub problems in a reverse topological order, that is tackling simpler problem first and guaranteing that simpler problems are all solved before increasing complexity.
This solution has low overhead but special care must be taken to the order of evaluation

- a **top down** approach, where we add a memoization steps, and that keep the natural. This allows unnessary branch, if any, to not be computed.


Both approaches yield the same asymptotical performance.



Examples
--------

let s = "Hello"

Those examples are taken from the book [Introduction to algorithm][cormen]

Rod cutting

Matrix product

Longest Common subsequence

Optimal binary search tree

[cormen]:http://en.wikipedia.org/wiki/Introduction_to_Algorithms

0 comments on commit db21b8f

Please sign in to comment.