-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error in literate script and add some test
- Loading branch information
Showing
7 changed files
with
200 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |