diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml new file mode 100644 index 0000000..20edf8a --- /dev/null +++ b/.github/workflows/_build.yml @@ -0,0 +1,41 @@ +name: Build +on: [push] +jobs: + + # BUILD + build: + name: Convert to HTML + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ZacJW/markdown-html-action@1.2.0 + with: + input_files: '[["docs/*.md"]]' + output_files: '["docs/index.html"]' + builtin_stylesheet: 'docs/fsharp-cheatsheet.css' + packages: 'pymdown-extensions' + extensions: '["pymdownx.extra"]' + - uses: actions/upload-pages-artifact@v2.0.0 + with: + path: 'docs/' + + # DEPLOY + deploy: + needs: build + + # Grant GITHUB_TOKEN the permissions required to make a Pages deployment + permissions: + pages: write # to deploy to Pages + id-token: write # to verify the deployment originates from an appropriate source + + # Deploy to the github-pages environment + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + # Specify runner + deployment step + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 # diff --git a/README.md b/README.md index f7fb2fe..19f08d0 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,27 @@ fsharp-cheatsheet ================= -A typesetted F# Cheatsheet in PDF and HTML formats using F# literate tools +An F# Cheatsheet in Markup and HTML formats ## Introduction -This is an attempt to replace the old and obsolete [F# Cheat Sheet](http://www.samskivert.com/code/fsharp/fsharp-cheat-sheet.pdf). - The raw content of this cheatsheet can be edited at [fsharp-cheatsheet.md](docs/fsharp-cheatsheet.md). -In order to build PDF and HTML documentation, please run the build script in [build.cmd](tools/build.cmd). We assume that `pdflatex.exe` is in PATH variable to be able generate PDF files. +HTML version is online at https://spiraloss.github.io/fsharp-cheatsheet + +## Contributing + +This resource was, is and should remain a community effort. If you're learning F# and something important you didn't learn about isn't covered, you're the very best person to point that out and phrase it in a way that someone new can get running with. If someone posts a PR, the more diversity of reviewers we get, the better. That said, the best PRs are small ones that touch one piece at a time and can hence be reviewed and merged rapidly. -PDF version can be downloaded [here](https://github.com/dungpa/fsharp-cheatsheet/raw/gh-pages/fsharp-cheatsheet.pdf). -HTML version is online at http://dungpa.github.io/fsharp-cheatsheet/. +Primary maintainer: @SpiralOSS (backup: @bartelink) -**Comments, suggestions and corrections are always welcome.** +## Acknowledgements + +Anh-Dung Phan (@dungpa) created and maintained the repo for many years before donating it to community ownership under fsprojects + +The original inspiration was the (now obsolete) http://www.samskivert.com/code/fsharp/fsharp-cheat-sheet.pdf ## License + The documents are available under Apache 2.0 license. For more information see the [License file](LICENSE.md). diff --git a/docs/fsharp-cheatsheet.css b/docs/fsharp-cheatsheet.css new file mode 100644 index 0000000..72a74ac --- /dev/null +++ b/docs/fsharp-cheatsheet.css @@ -0,0 +1,77 @@ +body { + font-family: 'Arial', sans-serif; + margin: 40px auto; + max-width: 800px; + line-height: 1.6; + color: #333; + background-color: #f7f7f7; + } + +h1, h2, h3, h4, h5, h6 { + margin-top: 1.2em; + } + +h1 { + font-size: 2em; + border-bottom: 2px solid #ddd; + } + +h2 { + font-size: 1.5em; + } + +h3 { + font-size: 1.3em; + } + +p { + margin-bottom: 1.2em; + } + +a { + color: #0077cc; + text-decoration: none; + } + +a:hover { + text-decoration: underline; + } + +strong { + font-weight: bold; + } + +em { + font-style: italic; + } + +ul, ol { + margin: 20px 0; + padding-left: 40px; + } + +li { + margin-bottom: 10px; + } + +blockquote { + border-left: 4px solid #ddd; + padding-left: 15px; + margin: 20px 0; + font-style: italic; + } + +code { + font-family: 'Courier New', monospace; + background-color: #eee; + padding: 2px 5px; + border-radius: 3px; + } + +pre { + font-family: 'Courier New', monospace; + background-color: #eee; + padding: 10px; + border-radius: 3px; + overflow-x: auto; + } diff --git a/docs/fsharp-cheatsheet.md b/docs/fsharp-cheatsheet.md index 7ad3142..dd58085 100644 --- a/docs/fsharp-cheatsheet.md +++ b/docs/fsharp-cheatsheet.md @@ -1,5 +1,8 @@ -This cheatsheet glances over some of the common syntax of [F# 3.0](http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/spec.html). -If you have any comments, corrections, or suggested additions, please open an issue or send a pull request to [https://github.com/dungpa/fsharp-cheatsheet](https://github.com/dungpa/fsharp-cheatsheet). +This cheatsheet aims to succinctly cover the most important aspects of [F# 6.0](http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/spec.html). + +The Microsoft [F# Documentation](https://learn.microsoft.com/en-us/dotnet/fsharp/) is complete and authoritative and has received a lot of love in recent years; it's well worth the time investment to read. Only after you've got the lowdown here of course ;) + + If you have any comments, corrections, or suggested additions, please open an issue or send a pull request to [https://github.com/fsprojects/fsharp-cheatsheet](https://github.com/fsprojects/fsharp-cheatsheet). Questions are best addressed via the [F# slack](https://fsharp.org/guides/slack) or the [F# discord](https://discord.me/fsharp). Contents -------- @@ -72,7 +75,7 @@ Other common examples are `F` or `f` for 32-bit floating-point numbers, `M` or ` // [fsi:val d : decimal = 0.7833M] // [fsi:val bi : System.Numerics.BigInteger = 9999] -See [Literals (MSDN)](http://msdn.microsoft.com/en-us/library/dd233193.aspx) for complete reference. +See [Literals (MS Learn)](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/literals) for complete reference. Functions --------- @@ -150,7 +153,7 @@ or implicitly via `function` keyword: | 1 -> 1 | n -> fib' (n - 1) + fib' (n - 2) -For more complete reference visit [Pattern Matching (MSDN)](http://msdn.microsoft.com/en-us/library/dd547125.aspx). +For more complete reference visit [Pattern Matching (MS Learn)](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/pattern-matching). Collections ----------- @@ -294,7 +297,7 @@ Records are essentially sealed classes with extra topping: default immutability, | Node(l, _, r) -> 1 + max (depth l) (depth r) | Leaf -> 0 -F# Core has a few built-in discriminated unions for error handling, e.g., [Option](http://msdn.microsoft.com/en-us/library/dd233245.aspx) and [Choice](http://msdn.microsoft.com/en-us/library/ee353439.aspx). +F# Core has built-in discriminated unions for error handling, e.g., [`option`](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/options) and [`Result`](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/results). let optionPatternMatch input = match input with @@ -466,12 +469,15 @@ Load another F# source file into FSI. #load "../lib/StringParsing.fs" Reference a .NET assembly (`/` symbol is recommended for Mono compatibility). - - #r "../lib/FSharp.Markdown.dll" +Reference a .NET assembly: + + #r "../lib/FSharp.Markdown.dll" Reference a nuget package - #r "nuget: FSharp.Data, 6.3.0" + #r "nuget:Serilog.Sinks.Console" // latest production release + #r "nuget: FSharp.Data, 6.3.0" // specific version + #r "nuget:Equinox, *-*" // latest version, including `-alpha`, `-rc` version etc Include a directory in assembly search paths. diff --git a/lib/FSharp.Markdown.dll b/lib/FSharp.Markdown.dll deleted file mode 100644 index 4342306..0000000 Binary files a/lib/FSharp.Markdown.dll and /dev/null differ diff --git a/templates/template-cheatsheet.tex b/templates/template-cheatsheet.tex deleted file mode 100644 index c76ccaa..0000000 --- a/templates/template-cheatsheet.tex +++ /dev/null @@ -1,184 +0,0 @@ -\documentclass[10pt,landscape]{article} -\usepackage{multicol} -\usepackage{calc} -\usepackage{ifthen} -\usepackage[landscape]{geometry} - -% To make this come out properly in landscape mode, do one of the following -% 1. -% pdflatex latexsheet.tex -% -% 2. -% latex latexsheet.tex -% dvips -P pdf -t landscape latexsheet.dvi -% ps2pdf latexsheet.ps - - -% If you're reading this, be prepared for confusion. Making this was -% a learning experience for me, and it shows. Much of the placement -% was hacked in; if you make it better, let me know... - - -% 2008-04 -% Changed page margin code to use the geometry package. Also added code for -% conditional page margins, depending on paper size. Thanks to Uwe Ziegenhagen -% for the suggestions. - -% 2006-08 -% Made changes based on suggestions from Gene Cooperman. - - -% To Do: -% \listoffigures \listoftables -% \setcounter{secnumdepth}{0} - - -% This sets page margins to .5 inch if using letter paper, and to 1cm -% if using A4 paper. (This probably isn't strictly necessary.) -% If using another size paper, use default 1cm margins. -\ifthenelse{\lengthtest { \paperwidth = 11in}} - { \geometry{top=.5in,left=.5in,right=.5in,bottom=.5in} } - {\ifthenelse{ \lengthtest{ \paperwidth = 297mm}} - {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} } - {\geometry{top=1cm,left=1cm,right=1cm,bottom=1cm} } - } - -% Turn off header and footer -\pagestyle{plain} - - -% Redefine section commands to use less space -\makeatletter -\renewcommand{\section}{\@startsection{section}{1}{0mm}% - {-1ex plus -.5ex minus -.2ex}% - {0.5ex plus .2ex}%x - {\normalfont\large\bfseries}} -\renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}% - {-1explus -.5ex minus -.2ex}% - {0.5ex plus .2ex}% - {\normalfont\normalsize\bfseries}} -\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}% - {-1ex plus -.5ex minus -.2ex}% - {1ex plus .2ex}% - {\normalfont\small\bfseries}} -\makeatother - -% Define BibTeX command -\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em - T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}} - -% Don't print section numbers -\setcounter{secnumdepth}{0} - - -\setlength{\parindent}{0pt} -\setlength{\parskip}{0pt plus 0.5ex} - -% --- Section for formatting F# code ------------------------- - -% Defining colors by names -\usepackage{xcolor} -% Verbatim enviroment -\usepackage{fancyvrb} -% Verbatim enviroment for unformatted source code -\usepackage{listings} -% Better font for backslash -\usepackage[T1]{fontenc} -\usepackage{hyperref} -% Providing more features than usual tabular -\usepackage{longtable} - -% NOTE: -% Remember to use big letters for color codes -% Reference at http://tex.stackexchange.com/questions/18008/use-css-style-color-specifications-in-xcolor - -% Identifiers -\newcommand{\id}[1]{\textcolor[HTML]{000000}{#1}} - -% Strings -\newcommand{\str}[1]{\textcolor[HTML]{A31515}{#1}} - -% Keywords -\newcommand{\kwd}[1]{\textcolor[HTML]{0000FF}{#1}} - -% Comments -\newcommand{\com}[1]{\textcolor[HTML]{008000}{#1}} - -% Operators -\newcommand{\ops}[1]{\textcolor[HTML]{000000}{#1}} - -% Numbers -\newcommand{\num}[1]{\textcolor[HTML]{000000}{#1}} - -% Line number -\newcommand{\lines}[1]{\textcolor[HTML]{96C2CD}{#1}} - -% Types or modules -\newcommand{\ltyp}[1]{\textcolor[HTML]{2B91AF}{#1}} - -% Functions -\newcommand{\lfun}[1]{\textcolor[HTML]{AA5500}{#1}} - -% Patterns -\newcommand{\lpat}[1]{\textcolor[HTML]{800080}{#1}} - -% Mutable vars -\newcommand{\lvar}[1]{\textbf{\textcolor[HTML]{000000}{#1}}} - -% Printf -\newcommand{\lprf}[1]{\textcolor[HTML]{2B91AF}{#1}} - -% Escaped characters -\newcommand{\lesc}[1]{\textcolor[HTML]{FF0080}{#1}} - -% Inactive elements -\newcommand{\inact}[1]{\textcolor[HTML]{808080}{#1}} - -% Preprocessors -\newcommand{\prep}[1]{\textcolor[HTML]{0000FF}{#1}} - -% fsi output -\newcommand{\fsi}[1]{\textcolor[HTML]{808080}{#1}} - -% Omitted parts -\newcommand{\omi}[1]{\textcolor[HTML]{808080}{#1}} - - -% Overriding color and style of line numbers -\renewcommand{\theFancyVerbLine}{ -\lines{\small \arabic{FancyVerbLine}:}} - -\lstset{% - backgroundcolor=\color{gray!15}, - basicstyle=\ttfamily, - breaklines=true, - columns=fullflexible -} - -% ----------------------------------------------------------------------- - -\begin{document} - -\raggedright -\footnotesize -\begin{multicols}{3} - - -% multicol parameters -% These lengths are set only within the two main columns -%\setlength{\columnseprule}{0.25pt} -\setlength{\premulticols}{1pt} -\setlength{\postmulticols}{1pt} -\setlength{\multicolsep}{1pt} -\setlength{\columnsep}{2pt} - -\begin{center} - \Large{{project-name}} \\ -\end{center} - -{contents} - -{tooltips} - -\end{multicols} -\end{document} diff --git a/templates/template-project.html b/templates/template-project.html deleted file mode 100644 index c116c20..0000000 --- a/templates/template-project.html +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - {page-title} - - - - - - - - - - - - - -
-
- -

{project-name}

-
-
- -
- Fork me on GitHub - - diff --git a/tools/.nuget/NuGet.Config b/tools/.nuget/NuGet.Config deleted file mode 100644 index 67f8ea0..0000000 --- a/tools/.nuget/NuGet.Config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/tools/.nuget/NuGet.exe b/tools/.nuget/NuGet.exe deleted file mode 100644 index cb3ed03..0000000 Binary files a/tools/.nuget/NuGet.exe and /dev/null differ diff --git a/tools/.nuget/NuGet.targets b/tools/.nuget/NuGet.targets deleted file mode 100644 index 46a1b6c..0000000 --- a/tools/.nuget/NuGet.targets +++ /dev/null @@ -1,133 +0,0 @@ - - - - $(MSBuildProjectDirectory)\..\ - - - false - - - false - - - true - - - false - - - - - - - - - - - $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) - $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) - - - - - $(SolutionDir).nuget - packages.config - - - - - $(NuGetToolsPath)\NuGet.exe - @(PackageSource) - - "$(NuGetExePath)" - mono --runtime=v4.0.30319 $(NuGetExePath) - - $(TargetDir.Trim('\\')) - - -RequireConsent - -NonInteractive - - - $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir "$(SolutionDir) " - $(NuGetCommand) pack "$(ProjectPath)" -Properties Configuration=$(Configuration) $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols - - - - RestorePackages; - $(BuildDependsOn); - - - - - $(BuildDependsOn); - BuildPackage; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tools/build.cmd b/tools/build.cmd deleted file mode 100644 index 0f495f8..0000000 --- a/tools/build.cmd +++ /dev/null @@ -1,6 +0,0 @@ -@echo off -cls -if not exist packages\FAKE\tools\Fake.exe ( - .nuget\nuget.exe install FAKE -OutputDirectory packages -ExcludeVersion -) -packages\FAKE\tools\FAKE.exe build.fsx %* \ No newline at end of file diff --git a/tools/build.fsx b/tools/build.fsx deleted file mode 100644 index 37a0a98..0000000 --- a/tools/build.fsx +++ /dev/null @@ -1,66 +0,0 @@ -// -------------------------------------------------------------------------------------- -// FAKE build script -// -------------------------------------------------------------------------------------- - -#r @"packages/FAKE/tools/FakeLib.dll" -open Fake -open Fake.Git -open System - -// Git configuration (used for publishing documentation in gh-pages branch) -// The profile where the project is posted -let gitHome = "https://github.com/dungpa" -// The name of the project on GitHub -let gitName = "fsharp-cheatsheet" -let cloneUrl = "git@github.com:dungpa/fsharp-cheatsheet.git" - -Environment.CurrentDirectory <- __SOURCE_DIRECTORY__ - -// -------------------------------------------------------------------------------------- -// Clean build results & restore NuGet packages - -Target "Clean" (fun _ -> - CleanDirs ["temp"] -) - -Target "RestorePackages" (fun _ -> - !! "./**/packages.config" - |> Seq.iter (RestorePackage (fun p -> { p with ToolPath = "./.nuget/NuGet.exe" })) -) - -// -------------------------------------------------------------------------------------- -// Generate the documentation - -Target "GenerateDocs" (fun _ -> - executeFSIWithArgs __SOURCE_DIRECTORY__ "generate.fsx" ["--define:RELEASE"] [] |> ignore -) - -// -------------------------------------------------------------------------------------- -// Release Script - -Target "ReleaseDocs" (fun _ -> - let tempDocsDir = "temp/gh-pages" - CleanDir tempDocsDir - Repository.cloneSingleBranch "" cloneUrl "gh-pages" tempDocsDir - - fullclean tempDocsDir - CopyRecursive "../docs/output" tempDocsDir true |> tracefn "%A" - StageAll tempDocsDir - Commit tempDocsDir (sprintf "Update generated documentation for F# CheatSheet") - Branches.push tempDocsDir -) - -// -------------------------------------------------------------------------------------- -// Run all targets by default. Invoke 'build ' to override - -Target "All" DoNothing - -"Clean" - ==> "RestorePackages" - ==> "All" - -"All" - ==> "GenerateDocs" - ==> "ReleaseDocs" - -RunTargetOrDefault "GenerateDocs" \ No newline at end of file diff --git a/tools/generate.fsx b/tools/generate.fsx deleted file mode 100644 index 79e3b41..0000000 --- a/tools/generate.fsx +++ /dev/null @@ -1,71 +0,0 @@ -#load "packages/FSharp.Formatting.2.9.6/FSharp.Formatting.fsx" - -#r "packages/FAKE/tools/FakeLib.dll" - -open Fake -open System.IO -open Fake.FileHelper -open FSharp.Literate -open System.Diagnostics - -let source = __SOURCE_DIRECTORY__ -let sources = source @@ "../docs" -let output = source @@ "../docs/output" -let formatting = source @@ "packages/FSharp.Formatting.2.9.6" - -let copyFiles() = - ensureDirectory (output @@ "content") - CopyRecursive (formatting @@ "styles") (output @@ "content") true - |> Log "Copying styles and scripts: " - -let generateHtmlDoc() = - let template = source @@ "../templates/template-project.html" - - // Additional strings to be replaced in the HTML template - let projInfo = - [ "page-description", "A typesetted F# Cheatsheet \ - in PDF and HTML formats using F# literate tools." - "page-title", "fsharp-cheatsheet" - "page-author", "Anh-Dung Phan" - "github-link", "https://github.com/dungpa/fsharp-cheatsheet" - "project-name", "F# Cheatsheet" ] - - printfn "Generate index.html" - Literate.ProcessMarkdown - (sources @@ "fsharp-cheatsheet.md", template, - output @@ "index.html", OutputKind.Html, - includeSource = true, lineNumbers = false, replacements = projInfo) - -let createPDF fileName = - use p = new Process() - // Assume that pdflatex is in the path - p.StartInfo.FileName <- "pdflatex.exe" - p.StartInfo.Arguments <- sprintf "-output-directory=%s %s" (Path.GetDirectoryName(fileName)) fileName - p.StartInfo.UseShellExecute <- false - p.StartInfo.RedirectStandardOutput <- false - p.Start() |> ignore - p.WaitForExit() - for ext in ["aux"; "out"; "log"] do - let auxFile = Path.ChangeExtension(fileName, ext) - printfn "Delete auxiliary file: %s" auxFile - File.Delete(auxFile) - -let generatePDFDoc() = - let template = source @@ "../templates/template-cheatsheet.tex" - - // These strings have to be well-formed in LaTeX - let projInfo = [ "project-name", "F\# Cheatsheet" ] - - printfn "Generate fsharp-cheatsheet.tex" - Literate.ProcessMarkdown - (sources @@ "fsharp-cheatsheet.md", template, - output @@ "fsharp-cheatsheet.tex", OutputKind.Latex, - includeSource = true, lineNumbers = false, replacements = projInfo) - createPDF (output @@ "fsharp-cheatsheet.tex") - - -#time "on";; - -copyFiles();; -generateHtmlDoc();; -generatePDFDoc();; diff --git a/tools/packages.config b/tools/packages.config deleted file mode 100644 index efb006d..0000000 --- a/tools/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file