├── book ├── FPLean │ ├── Basic.lean │ ├── Meta │ │ └── NameSuffixMap.lean │ ├── FunctorApplicativeMonad │ │ └── Conveniences.lean │ ├── Meta.lean │ ├── Examples │ │ ├── Commands │ │ │ └── Env.lean │ │ └── Commands.lean │ ├── HelloWorld.lean │ ├── MonadTransformers.lean │ ├── Acks.lean │ ├── GettingToKnow.lean │ ├── ProgramsProofs.lean │ ├── FunctorApplicativeMonad.lean │ ├── ProgramsProofs │ │ └── Fin.lean │ ├── NextSteps.lean │ ├── Monads │ │ └── Summary.lean │ ├── MonadTransformers │ │ └── Summary.lean │ ├── GettingToKnow │ │ └── Types.lean │ └── DependentTypes.lean ├── README.md ├── lean-toolchain ├── static │ ├── fonts │ │ ├── source-sans │ │ │ ├── OTF │ │ │ │ ├── SourceSans3-It.otf │ │ │ │ ├── SourceSans3-Bold.otf │ │ │ │ ├── SourceSans3-Black.otf │ │ │ │ ├── SourceSans3-BlackIt.otf │ │ │ │ ├── SourceSans3-BoldIt.otf │ │ │ │ ├── SourceSans3-Light.otf │ │ │ │ ├── SourceSans3-LightIt.otf │ │ │ │ ├── SourceSans3-Medium.otf │ │ │ │ ├── SourceSans3-Regular.otf │ │ │ │ ├── SourceSans3-MediumIt.otf │ │ │ │ ├── SourceSans3-Semibold.otf │ │ │ │ ├── SourceSans3-ExtraLight.otf │ │ │ │ ├── SourceSans3-ExtraLightIt.otf │ │ │ │ └── SourceSans3-SemiboldIt.otf │ │ │ ├── TTF │ │ │ │ ├── SourceSans3-It.ttf │ │ │ │ ├── SourceSans3-Bold.ttf │ │ │ │ ├── SourceSans3-Black.ttf │ │ │ │ ├── SourceSans3-BlackIt.ttf │ │ │ │ ├── SourceSans3-BoldIt.ttf │ │ │ │ ├── SourceSans3-Light.ttf │ │ │ │ ├── SourceSans3-LightIt.ttf │ │ │ │ ├── SourceSans3-Medium.ttf │ │ │ │ ├── SourceSans3-Regular.ttf │ │ │ │ ├── SourceSans3-MediumIt.ttf │ │ │ │ ├── SourceSans3-Semibold.ttf │ │ │ │ ├── SourceSans3-ExtraLight.ttf │ │ │ │ ├── SourceSans3-ExtraLightIt.ttf │ │ │ │ └── SourceSans3-SemiboldIt.ttf │ │ │ ├── VF │ │ │ │ ├── SourceSans3VF-Italic.otf │ │ │ │ ├── SourceSans3VF-Italic.ttf │ │ │ │ ├── SourceSans3VF-Upright.otf │ │ │ │ └── SourceSans3VF-Upright.ttf │ │ │ ├── WOFF │ │ │ │ ├── OTF │ │ │ │ │ ├── SourceSans3-It.otf.woff │ │ │ │ │ ├── SourceSans3-Bold.otf.woff │ │ │ │ │ ├── SourceSans3-Black.otf.woff │ │ │ │ │ ├── SourceSans3-BlackIt.otf.woff │ │ │ │ │ ├── SourceSans3-BoldIt.otf.woff │ │ │ │ │ ├── SourceSans3-Light.otf.woff │ │ │ │ │ ├── SourceSans3-LightIt.otf.woff │ │ │ │ │ ├── SourceSans3-Medium.otf.woff │ │ │ │ │ ├── SourceSans3-Regular.otf.woff │ │ │ │ │ ├── SourceSans3-MediumIt.otf.woff │ │ │ │ │ ├── SourceSans3-Semibold.otf.woff │ │ │ │ │ ├── SourceSans3-ExtraLight.otf.woff │ │ │ │ │ ├── SourceSans3-ExtraLightIt.otf.woff │ │ │ │ │ └── SourceSans3-SemiboldIt.otf.woff │ │ │ │ ├── TTF │ │ │ │ │ ├── SourceSans3-It.ttf.woff │ │ │ │ │ ├── SourceSans3-Bold.ttf.woff │ │ │ │ │ ├── SourceSans3-Black.ttf.woff │ │ │ │ │ ├── SourceSans3-BlackIt.ttf.woff │ │ │ │ │ ├── SourceSans3-BoldIt.ttf.woff │ │ │ │ │ ├── SourceSans3-Light.ttf.woff │ │ │ │ │ ├── SourceSans3-LightIt.ttf.woff │ │ │ │ │ ├── SourceSans3-Medium.ttf.woff │ │ │ │ │ ├── SourceSans3-Regular.ttf.woff │ │ │ │ │ ├── SourceSans3-MediumIt.ttf.woff │ │ │ │ │ ├── SourceSans3-Semibold.ttf.woff │ │ │ │ │ ├── SourceSans3-ExtraLight.ttf.woff │ │ │ │ │ ├── SourceSans3-ExtraLightIt.ttf.woff │ │ │ │ │ └── SourceSans3-SemiboldIt.ttf.woff │ │ │ │ └── VF │ │ │ │ │ ├── SourceSans3VF-Italic.otf.woff │ │ │ │ │ ├── SourceSans3VF-Italic.ttf.woff │ │ │ │ │ ├── SourceSans3VF-Upright.otf.woff │ │ │ │ │ └── SourceSans3VF-Upright.ttf.woff │ │ │ ├── WOFF2 │ │ │ │ ├── OTF │ │ │ │ │ ├── SourceSans3-It.otf.woff2 │ │ │ │ │ ├── SourceSans3-Black.otf.woff2 │ │ │ │ │ ├── SourceSans3-Bold.otf.woff2 │ │ │ │ │ ├── SourceSans3-Light.otf.woff2 │ │ │ │ │ ├── SourceSans3-BlackIt.otf.woff2 │ │ │ │ │ ├── SourceSans3-BoldIt.otf.woff2 │ │ │ │ │ ├── SourceSans3-LightIt.otf.woff2 │ │ │ │ │ ├── SourceSans3-Medium.otf.woff2 │ │ │ │ │ ├── SourceSans3-Regular.otf.woff2 │ │ │ │ │ ├── SourceSans3-ExtraLight.otf.woff2 │ │ │ │ │ ├── SourceSans3-MediumIt.otf.woff2 │ │ │ │ │ ├── SourceSans3-Semibold.otf.woff2 │ │ │ │ │ ├── SourceSans3-SemiboldIt.otf.woff2 │ │ │ │ │ └── SourceSans3-ExtraLightIt.otf.woff2 │ │ │ │ ├── TTF │ │ │ │ │ ├── SourceSans3-It.ttf.woff2 │ │ │ │ │ ├── SourceSans3-Black.ttf.woff2 │ │ │ │ │ ├── SourceSans3-Bold.ttf.woff2 │ │ │ │ │ ├── SourceSans3-Light.ttf.woff2 │ │ │ │ │ ├── SourceSans3-BlackIt.ttf.woff2 │ │ │ │ │ ├── SourceSans3-BoldIt.ttf.woff2 │ │ │ │ │ ├── SourceSans3-LightIt.ttf.woff2 │ │ │ │ │ ├── SourceSans3-Medium.ttf.woff2 │ │ │ │ │ ├── SourceSans3-Regular.ttf.woff2 │ │ │ │ │ ├── SourceSans3-ExtraLight.ttf.woff2 │ │ │ │ │ ├── SourceSans3-MediumIt.ttf.woff2 │ │ │ │ │ ├── SourceSans3-Semibold.ttf.woff2 │ │ │ │ │ ├── SourceSans3-SemiboldIt.ttf.woff2 │ │ │ │ │ └── SourceSans3-ExtraLightIt.ttf.woff2 │ │ │ │ └── VF │ │ │ │ │ ├── SourceSans3VF-Italic.otf.woff2 │ │ │ │ │ ├── SourceSans3VF-Italic.ttf.woff2 │ │ │ │ │ ├── SourceSans3VF-Upright.otf.woff2 │ │ │ │ │ └── SourceSans3VF-Upright.ttf.woff2 │ │ │ ├── source-sans-3VF.css │ │ │ ├── source-sans-3.css │ │ │ └── LICENSE.md │ │ ├── source-serif │ │ │ ├── OTF │ │ │ │ ├── SourceSerif4-It.otf │ │ │ │ ├── SourceSerif4-Black.otf │ │ │ │ ├── SourceSerif4-Bold.otf │ │ │ │ ├── SourceSerif4-Light.otf │ │ │ │ ├── SourceSerif4-BlackIt.otf │ │ │ │ ├── SourceSerif4-BoldIt.otf │ │ │ │ ├── SourceSerif4-LightIt.otf │ │ │ │ ├── SourceSerif4-Regular.otf │ │ │ │ ├── SourceSerif4-ExtraLight.otf │ │ │ │ ├── SourceSerif4-Semibold.otf │ │ │ │ ├── SourceSerif4-SemiboldIt.otf │ │ │ │ └── SourceSerif4-ExtraLightIt.otf │ │ │ ├── TTF │ │ │ │ ├── SourceSerif4-It.ttf │ │ │ │ ├── SourceSerif4-Black.ttf │ │ │ │ ├── SourceSerif4-Bold.ttf │ │ │ │ ├── SourceSerif4-Light.ttf │ │ │ │ ├── SourceSerif4-BlackIt.ttf │ │ │ │ ├── SourceSerif4-BoldIt.ttf │ │ │ │ ├── SourceSerif4-LightIt.ttf │ │ │ │ ├── SourceSerif4-Regular.ttf │ │ │ │ ├── SourceSerif4-ExtraLight.ttf │ │ │ │ ├── SourceSerif4-Semibold.ttf │ │ │ │ ├── SourceSerif4-SemiboldIt.ttf │ │ │ │ └── SourceSerif4-ExtraLightIt.ttf │ │ │ ├── WOFF │ │ │ │ ├── OTF │ │ │ │ │ ├── SourceSerif4-It.otf.woff │ │ │ │ │ ├── SourceSerif4-Black.otf.woff │ │ │ │ │ ├── SourceSerif4-Bold.otf.woff │ │ │ │ │ ├── SourceSerif4-Light.otf.woff │ │ │ │ │ ├── SourceSerif4-BlackIt.otf.woff │ │ │ │ │ ├── SourceSerif4-BoldIt.otf.woff │ │ │ │ │ ├── SourceSerif4-LightIt.otf.woff │ │ │ │ │ ├── SourceSerif4-Regular.otf.woff │ │ │ │ │ ├── SourceSerif4-ExtraLight.otf.woff │ │ │ │ │ ├── SourceSerif4-Semibold.otf.woff │ │ │ │ │ ├── SourceSerif4-SemiboldIt.otf.woff │ │ │ │ │ └── SourceSerif4-ExtraLightIt.otf.woff │ │ │ │ └── TTF │ │ │ │ │ ├── SourceSerif4-It.ttf.woff │ │ │ │ │ ├── SourceSerif4-Black.ttf.woff │ │ │ │ │ ├── SourceSerif4-Bold.ttf.woff │ │ │ │ │ ├── SourceSerif4-Light.ttf.woff │ │ │ │ │ ├── SourceSerif4-BlackIt.ttf.woff │ │ │ │ │ ├── SourceSerif4-BoldIt.ttf.woff │ │ │ │ │ ├── SourceSerif4-LightIt.ttf.woff │ │ │ │ │ ├── SourceSerif4-Regular.ttf.woff │ │ │ │ │ ├── SourceSerif4-ExtraLight.ttf.woff │ │ │ │ │ ├── SourceSerif4-Semibold.ttf.woff │ │ │ │ │ ├── SourceSerif4-SemiboldIt.ttf.woff │ │ │ │ │ └── SourceSerif4-ExtraLightIt.ttf.woff │ │ │ ├── WOFF2 │ │ │ │ ├── OTF │ │ │ │ │ ├── SourceSerif4-It.otf.woff2 │ │ │ │ │ ├── SourceSerif4-Black.otf.woff2 │ │ │ │ │ ├── SourceSerif4-Bold.otf.woff2 │ │ │ │ │ ├── SourceSerif4-Light.otf.woff2 │ │ │ │ │ ├── SourceSerif4-BlackIt.otf.woff2 │ │ │ │ │ ├── SourceSerif4-BoldIt.otf.woff2 │ │ │ │ │ ├── SourceSerif4-LightIt.otf.woff2 │ │ │ │ │ ├── SourceSerif4-Regular.otf.woff2 │ │ │ │ │ ├── SourceSerif4-Semibold.otf.woff2 │ │ │ │ │ ├── SourceSerif4-ExtraLight.otf.woff2 │ │ │ │ │ ├── SourceSerif4-SemiboldIt.otf.woff2 │ │ │ │ │ └── SourceSerif4-ExtraLightIt.otf.woff2 │ │ │ │ └── TTF │ │ │ │ │ ├── SourceSerif4-It.ttf.woff2 │ │ │ │ │ ├── SourceSerif4-Black.ttf.woff2 │ │ │ │ │ ├── SourceSerif4-Bold.ttf.woff2 │ │ │ │ │ ├── SourceSerif4-Light.ttf.woff2 │ │ │ │ │ ├── SourceSerif4-BlackIt.ttf.woff2 │ │ │ │ │ ├── SourceSerif4-BoldIt.ttf.woff2 │ │ │ │ │ ├── SourceSerif4-LightIt.ttf.woff2 │ │ │ │ │ ├── SourceSerif4-Regular.ttf.woff2 │ │ │ │ │ ├── SourceSerif4-Semibold.ttf.woff2 │ │ │ │ │ ├── SourceSerif4-ExtraLight.ttf.woff2 │ │ │ │ │ ├── SourceSerif4-SemiboldIt.ttf.woff2 │ │ │ │ │ └── SourceSerif4-ExtraLightIt.ttf.woff2 │ │ │ └── LICENSE.md │ │ ├── source-code-pro │ │ │ ├── OTF │ │ │ │ ├── SourceCodePro-It.otf │ │ │ │ ├── SourceCodePro-Black.otf │ │ │ │ ├── SourceCodePro-Bold.otf │ │ │ │ ├── SourceCodePro-BoldIt.otf │ │ │ │ ├── SourceCodePro-Light.otf │ │ │ │ ├── SourceCodePro-Medium.otf │ │ │ │ ├── SourceCodePro-BlackIt.otf │ │ │ │ ├── SourceCodePro-LightIt.otf │ │ │ │ ├── SourceCodePro-MediumIt.otf │ │ │ │ ├── SourceCodePro-Regular.otf │ │ │ │ ├── SourceCodePro-Semibold.otf │ │ │ │ ├── SourceCodePro-ExtraLight.otf │ │ │ │ ├── SourceCodePro-SemiboldIt.otf │ │ │ │ └── SourceCodePro-ExtraLightIt.otf │ │ │ ├── TTF │ │ │ │ ├── SourceCodePro-It.ttf │ │ │ │ ├── SourceCodePro-Black.ttf │ │ │ │ ├── SourceCodePro-Bold.ttf │ │ │ │ ├── SourceCodePro-BoldIt.ttf │ │ │ │ ├── SourceCodePro-Light.ttf │ │ │ │ ├── SourceCodePro-Medium.ttf │ │ │ │ ├── SourceCodePro-BlackIt.ttf │ │ │ │ ├── SourceCodePro-LightIt.ttf │ │ │ │ ├── SourceCodePro-MediumIt.ttf │ │ │ │ ├── SourceCodePro-Regular.ttf │ │ │ │ ├── SourceCodePro-Semibold.ttf │ │ │ │ ├── SourceCodePro-ExtraLight.ttf │ │ │ │ ├── SourceCodePro-SemiboldIt.ttf │ │ │ │ └── SourceCodePro-ExtraLightIt.ttf │ │ │ ├── WOFF │ │ │ │ ├── OTF │ │ │ │ │ ├── SourceCodePro-It.otf.woff │ │ │ │ │ ├── SourceCodePro-Black.otf.woff │ │ │ │ │ ├── SourceCodePro-Bold.otf.woff │ │ │ │ │ ├── SourceCodePro-BoldIt.otf.woff │ │ │ │ │ ├── SourceCodePro-Light.otf.woff │ │ │ │ │ ├── SourceCodePro-Medium.otf.woff │ │ │ │ │ ├── SourceCodePro-BlackIt.otf.woff │ │ │ │ │ ├── SourceCodePro-LightIt.otf.woff │ │ │ │ │ ├── SourceCodePro-MediumIt.otf.woff │ │ │ │ │ ├── SourceCodePro-Regular.otf.woff │ │ │ │ │ ├── SourceCodePro-Semibold.otf.woff │ │ │ │ │ ├── SourceCodePro-ExtraLight.otf.woff │ │ │ │ │ ├── SourceCodePro-SemiboldIt.otf.woff │ │ │ │ │ └── SourceCodePro-ExtraLightIt.otf.woff │ │ │ │ └── TTF │ │ │ │ │ ├── SourceCodePro-It.ttf.woff │ │ │ │ │ ├── SourceCodePro-Black.ttf.woff │ │ │ │ │ ├── SourceCodePro-Bold.ttf.woff │ │ │ │ │ ├── SourceCodePro-BoldIt.ttf.woff │ │ │ │ │ ├── SourceCodePro-Light.ttf.woff │ │ │ │ │ ├── SourceCodePro-Medium.ttf.woff │ │ │ │ │ ├── SourceCodePro-BlackIt.ttf.woff │ │ │ │ │ ├── SourceCodePro-LightIt.ttf.woff │ │ │ │ │ ├── SourceCodePro-MediumIt.ttf.woff │ │ │ │ │ ├── SourceCodePro-Regular.ttf.woff │ │ │ │ │ ├── SourceCodePro-Semibold.ttf.woff │ │ │ │ │ ├── SourceCodePro-ExtraLight.ttf.woff │ │ │ │ │ ├── SourceCodePro-SemiboldIt.ttf.woff │ │ │ │ │ └── SourceCodePro-ExtraLightIt.ttf.woff │ │ │ └── WOFF2 │ │ │ │ ├── OTF │ │ │ │ ├── SourceCodePro-Bold.otf.woff2 │ │ │ │ ├── SourceCodePro-It.otf.woff2 │ │ │ │ ├── SourceCodePro-Black.otf.woff2 │ │ │ │ ├── SourceCodePro-BoldIt.otf.woff2 │ │ │ │ ├── SourceCodePro-Light.otf.woff2 │ │ │ │ ├── SourceCodePro-Medium.otf.woff2 │ │ │ │ ├── SourceCodeVF-Italic.otf.woff2 │ │ │ │ ├── SourceCodeVF-Upright.otf.woff2 │ │ │ │ ├── SourceCodePro-BlackIt.otf.woff2 │ │ │ │ ├── SourceCodePro-LightIt.otf.woff2 │ │ │ │ ├── SourceCodePro-MediumIt.otf.woff2 │ │ │ │ ├── SourceCodePro-Regular.otf.woff2 │ │ │ │ ├── SourceCodePro-Semibold.otf.woff2 │ │ │ │ ├── SourceCodePro-ExtraLight.otf.woff2 │ │ │ │ ├── SourceCodePro-SemiboldIt.otf.woff2 │ │ │ │ └── SourceCodePro-ExtraLightIt.otf.woff2 │ │ │ │ └── TTF │ │ │ │ ├── SourceCodePro-Bold.ttf.woff2 │ │ │ │ ├── SourceCodePro-It.ttf.woff2 │ │ │ │ ├── SourceCodePro-Black.ttf.woff2 │ │ │ │ ├── SourceCodePro-BoldIt.ttf.woff2 │ │ │ │ ├── SourceCodePro-Light.ttf.woff2 │ │ │ │ ├── SourceCodePro-Medium.ttf.woff2 │ │ │ │ ├── SourceCodeVF-Italic.ttf.woff2 │ │ │ │ ├── SourceCodeVF-Upright.ttf.woff2 │ │ │ │ ├── SourceCodePro-BlackIt.ttf.woff2 │ │ │ │ ├── SourceCodePro-LightIt.ttf.woff2 │ │ │ │ ├── SourceCodePro-MediumIt.ttf.woff2 │ │ │ │ ├── SourceCodePro-Regular.ttf.woff2 │ │ │ │ ├── SourceCodePro-Semibold.ttf.woff2 │ │ │ │ ├── SourceCodePro-ExtraLight.ttf.woff2 │ │ │ │ ├── SourceCodePro-SemiboldIt.ttf.woff2 │ │ │ │ └── SourceCodePro-ExtraLightIt.ttf.woff2 │ │ └── noto-sans-mono │ │ │ ├── NotoSansMono-VariableFont_wdth,wght.ttf │ │ │ ├── noto-sans-mono.css │ │ │ └── OFL.txt │ └── theme.css ├── .verso │ └── verso-xref-manifest.json ├── verso-sources.json ├── Main.lean ├── lake-manifest.json ├── FPLean.lean └── lakefile.lean ├── examples ├── README.rst ├── first-lake │ ├── .gitignore │ └── expected │ │ ├── Greeting │ │ └── Basic.lean │ │ ├── Main.lean │ │ ├── Greeting.lean │ │ └── lakefile.toml ├── Examples │ ├── ProgramsProofs.lean │ ├── Doug1.lean │ ├── ProgramsProofs │ │ ├── TCOTest.lean │ │ ├── Div.lean │ │ ├── Fin.lean │ │ └── InstrumentedInsertionSort.lean │ ├── SpecialTypes.lean │ ├── MonadTransformers.lean │ ├── MonadTransformers │ │ └── Conveniences.lean │ ├── Classes │ │ └── Even.lean │ ├── HelloWorld.lean │ ├── Monads │ │ ├── Do.lean │ │ ├── Conveniences.lean │ │ └── IO.lean │ └── DependentTypes │ │ └── IndicesParameters.lean ├── feline │ ├── 1 │ │ ├── lean-toolchain │ │ ├── Main.lean │ │ └── lakefile.toml │ └── 2 │ │ ├── Main.lean │ │ ├── test2.txt │ │ ├── test1.txt │ │ ├── expected │ │ ├── test12.txt │ │ └── test1purr2.txt │ │ ├── lakefile.toml │ │ └── FelineLib.lean ├── .gitignore ├── formio │ ├── expected │ └── test-data ├── lean-toolchain ├── second-lake │ └── greeting │ │ ├── Greeting.lean │ │ ├── lean-toolchain │ │ ├── Greeting │ │ └── Smile.lean │ │ ├── Aux.lean │ │ ├── Main.lean │ │ ├── lakefile.lean │ │ └── lake-manifest.json ├── early-return │ ├── .gitignore │ ├── expected │ ├── too-many-args │ ├── no-name │ ├── run │ ├── lakefile.lean │ └── EarlyReturn.lean ├── simple-hello │ └── Hello.lean ├── Main.lean ├── sort-demo │ ├── run-usage │ └── test-data ├── hello-name │ ├── run │ └── HelloName.lean ├── inorder_python │ ├── expected │ └── inordernumbering.py ├── lake-manifest.json ├── ForMIO.lean ├── Examples.lean └── lakefile.lean ├── .gitignore ├── .github └── ISSUE_TEMPLATE │ ├── technical-error.md │ └── typo.md ├── README.md └── CONTRIBUTING.md /book/FPLean/Basic.lean: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /book/README.md: -------------------------------------------------------------------------------- 1 | # book -------------------------------------------------------------------------------- /examples/README.rst: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/first-lake/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /book/FPLean/Meta/NameSuffixMap.lean: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/Examples/ProgramsProofs.lean: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/feline/2/Main.lean: -------------------------------------------------------------------------------- 1 | import FelineLib 2 | -------------------------------------------------------------------------------- /examples/feline/2/test2.txt: -------------------------------------------------------------------------------- 1 | and curl up! 2 | -------------------------------------------------------------------------------- /book/FPLean/FunctorApplicativeMonad/Conveniences.lean: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /book/lean-toolchain: -------------------------------------------------------------------------------- 1 | leanprover/lean4:v4.27.0-rc1 2 | -------------------------------------------------------------------------------- /examples/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /lean_packages 3 | -------------------------------------------------------------------------------- /examples/feline/1/lean-toolchain: -------------------------------------------------------------------------------- 1 | ../../lean-toolchain -------------------------------------------------------------------------------- /examples/formio/expected: -------------------------------------------------------------------------------- 1 | Hello! 2 | abc123 3 | Ok 4 | -------------------------------------------------------------------------------- /examples/lean-toolchain: -------------------------------------------------------------------------------- 1 | leanprover/lean4:4.26.0 2 | -------------------------------------------------------------------------------- /examples/feline/2/test1.txt: -------------------------------------------------------------------------------- 1 | It's time to find a warm spot 2 | -------------------------------------------------------------------------------- /examples/second-lake/greeting/Greeting.lean: -------------------------------------------------------------------------------- 1 | def hello := "world" -------------------------------------------------------------------------------- /examples/early-return/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /lake-packages/* 3 | -------------------------------------------------------------------------------- /examples/first-lake/expected/Greeting/Basic.lean: -------------------------------------------------------------------------------- 1 | def hello := "world" -------------------------------------------------------------------------------- /book/FPLean/Meta.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | 3 | namespace FPLean 4 | -------------------------------------------------------------------------------- /examples/second-lake/greeting/lean-toolchain: -------------------------------------------------------------------------------- 1 | leanprover/lean4:v4.23.0 2 | -------------------------------------------------------------------------------- /examples/formio/test-data: -------------------------------------------------------------------------------- 1 | Hello! 2 | !!!!! 3 | 12345 4 | abc123 5 | 6 | Ok 7 | -------------------------------------------------------------------------------- /examples/Examples/Doug1.lean: -------------------------------------------------------------------------------- 1 | import DirTree 2 | 3 | def main := DirTree.Old.main 4 | -------------------------------------------------------------------------------- /examples/feline/1/Main.lean: -------------------------------------------------------------------------------- 1 | def main : IO Unit := 2 | IO.println s!"Hello, cats!" 3 | -------------------------------------------------------------------------------- /examples/feline/2/expected/test12.txt: -------------------------------------------------------------------------------- 1 | It's time to find a warm spot 2 | and curl up! 3 | -------------------------------------------------------------------------------- /examples/simple-hello/Hello.lean: -------------------------------------------------------------------------------- 1 | def main : IO Unit := IO.println "Hello, world!" 2 | -------------------------------------------------------------------------------- /examples/early-return/expected: -------------------------------------------------------------------------------- 1 | How would you like to be addressed? 2 | David 3 | Hello, David! -------------------------------------------------------------------------------- /examples/second-lake/greeting/Greeting/Smile.lean: -------------------------------------------------------------------------------- 1 | def Expression.happy : String := "a big smile" 2 | -------------------------------------------------------------------------------- /examples/feline/2/expected/test1purr2.txt: -------------------------------------------------------------------------------- 1 | It's time to find a warm spot 2 | and purr 3 | and curl up! 4 | -------------------------------------------------------------------------------- /examples/Main.lean: -------------------------------------------------------------------------------- 1 | import Examples 2 | 3 | def main : IO Unit := do 4 | IO.println "The code here is for the book" 5 | -------------------------------------------------------------------------------- /examples/first-lake/expected/Main.lean: -------------------------------------------------------------------------------- 1 | import Greeting 2 | 3 | def main : IO Unit := 4 | IO.println s!"Hello, {hello}!" 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | functional-programming-lean/book 2 | *~ 3 | *# 4 | .#* 5 | _out/ 6 | *.olean 7 | .DS_Store 8 | .lake 9 | venv 10 | -------------------------------------------------------------------------------- /examples/second-lake/greeting/Aux.lean: -------------------------------------------------------------------------------- 1 | example : Nat → Float := Nat.toFloat 2 | open Nat (toFloat) 3 | example : Nat → Float := toFloat 4 | -------------------------------------------------------------------------------- /examples/sort-demo/run-usage: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect -f 2 | log_user 0 3 | spawn sort 4 | log_user 1 5 | 6 | expect "Expected single argument" 7 | -------------------------------------------------------------------------------- /examples/sort-demo/test-data: -------------------------------------------------------------------------------- 1 | schist 2 | feldspar 3 | diorite 4 | pumice 5 | obsidian 6 | shale 7 | gneiss 8 | marble 9 | flint 10 | -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-It.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-It.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-It.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-It.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-Bold.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-Bold.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/OTF/SourceSerif4-It.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/OTF/SourceSerif4-It.otf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/TTF/SourceSerif4-It.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/TTF/SourceSerif4-It.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-Black.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-Black.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-BlackIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-BlackIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-BoldIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-BoldIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-Light.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-Light.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-LightIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-LightIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-Medium.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-Medium.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-Regular.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-Black.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-Black.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-BlackIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-BlackIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-BoldIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-BoldIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-Light.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-LightIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-LightIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-Medium.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-Regular.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/VF/SourceSans3VF-Italic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/VF/SourceSans3VF-Italic.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/VF/SourceSans3VF-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/VF/SourceSans3VF-Italic.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/OTF/SourceSerif4-Black.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/OTF/SourceSerif4-Black.otf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/OTF/SourceSerif4-Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/OTF/SourceSerif4-Bold.otf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/OTF/SourceSerif4-Light.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/OTF/SourceSerif4-Light.otf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/TTF/SourceSerif4-Black.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/TTF/SourceSerif4-Black.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/TTF/SourceSerif4-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/TTF/SourceSerif4-Bold.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/TTF/SourceSerif4-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/TTF/SourceSerif4-Light.ttf -------------------------------------------------------------------------------- /examples/feline/1/lakefile.toml: -------------------------------------------------------------------------------- 1 | name = "feline" 2 | version = "0.1.0" 3 | defaultTargets = ["feline"] 4 | 5 | [[lean_exe]] 6 | name = "feline" 7 | root = "Main" 8 | -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-It.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-It.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-It.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-It.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-MediumIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-MediumIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-Semibold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-Semibold.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-MediumIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-MediumIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-Semibold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-Semibold.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/VF/SourceSans3VF-Upright.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/VF/SourceSans3VF-Upright.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/VF/SourceSans3VF-Upright.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/VF/SourceSans3VF-Upright.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/OTF/SourceSerif4-BlackIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/OTF/SourceSerif4-BlackIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/OTF/SourceSerif4-BoldIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/OTF/SourceSerif4-BoldIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/OTF/SourceSerif4-LightIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/OTF/SourceSerif4-LightIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/OTF/SourceSerif4-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/OTF/SourceSerif4-Regular.otf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/TTF/SourceSerif4-BlackIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/TTF/SourceSerif4-BlackIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/TTF/SourceSerif4-BoldIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/TTF/SourceSerif4-BoldIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/TTF/SourceSerif4-LightIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/TTF/SourceSerif4-LightIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/TTF/SourceSerif4-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/TTF/SourceSerif4-Regular.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-Black.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-Black.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-Bold.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-BoldIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-BoldIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-Light.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-Light.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-Medium.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-Medium.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-Black.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-Black.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-Bold.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-BoldIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-BoldIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-Light.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-Medium.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-ExtraLight.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-ExtraLight.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-ExtraLightIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-ExtraLightIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/OTF/SourceSans3-SemiboldIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/OTF/SourceSans3-SemiboldIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-ExtraLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-ExtraLight.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-ExtraLightIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-ExtraLightIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/TTF/SourceSans3-SemiboldIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/TTF/SourceSans3-SemiboldIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-It.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-It.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-It.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-It.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/OTF/SourceSerif4-ExtraLight.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/OTF/SourceSerif4-ExtraLight.otf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/OTF/SourceSerif4-Semibold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/OTF/SourceSerif4-Semibold.otf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/OTF/SourceSerif4-SemiboldIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/OTF/SourceSerif4-SemiboldIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/TTF/SourceSerif4-ExtraLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/TTF/SourceSerif4-ExtraLight.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/TTF/SourceSerif4-Semibold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/TTF/SourceSerif4-Semibold.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/TTF/SourceSerif4-SemiboldIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/TTF/SourceSerif4-SemiboldIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-BlackIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-BlackIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-LightIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-LightIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-MediumIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-MediumIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-Regular.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-Semibold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-Semibold.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-BlackIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-BlackIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-LightIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-LightIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-MediumIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-MediumIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-Regular.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-Semibold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-Semibold.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-Bold.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-Bold.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-Bold.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-Bold.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-It.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-It.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-It.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-It.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/OTF/SourceSerif4-ExtraLightIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/OTF/SourceSerif4-ExtraLightIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/TTF/SourceSerif4-ExtraLightIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/TTF/SourceSerif4-ExtraLightIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-It.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-It.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-It.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-It.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-ExtraLight.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-ExtraLight.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-SemiboldIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-SemiboldIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-ExtraLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-ExtraLight.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-SemiboldIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-SemiboldIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-Black.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-Black.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-BlackIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-BlackIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-BoldIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-BoldIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-Light.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-Light.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-LightIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-LightIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-Medium.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-Medium.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-Regular.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-Regular.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-Black.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-Black.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-BlackIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-BlackIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-BoldIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-BoldIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-Light.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-Light.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-LightIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-LightIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-Medium.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-Medium.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-Regular.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-Regular.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/VF/SourceSans3VF-Italic.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/VF/SourceSans3VF-Italic.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/VF/SourceSans3VF-Italic.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/VF/SourceSans3VF-Italic.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-Black.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-Black.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-Bold.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-Bold.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-Light.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-Light.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-Black.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-Black.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-Bold.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-Bold.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-Light.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-Light.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-Black.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-Black.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-Bold.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-Bold.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-Light.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-Light.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-Black.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-Black.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-Bold.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-Bold.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-Light.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-Light.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-It.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-It.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-It.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-It.ttf.woff2 -------------------------------------------------------------------------------- /examples/early-return/too-many-args: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect -f 2 | log_user 0 3 | spawn lean --run EarlyReturn.lean David 4 | log_user 1 5 | 6 | expect "Expected no arguments, but got 1" 7 | -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/OTF/SourceCodePro-ExtraLightIt.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/OTF/SourceCodePro-ExtraLightIt.otf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/TTF/SourceCodePro-ExtraLightIt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/TTF/SourceCodePro-ExtraLightIt.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-It.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-It.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-It.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-It.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-MediumIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-MediumIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-Semibold.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-Semibold.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-MediumIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-MediumIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-Semibold.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-Semibold.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/VF/SourceSans3VF-Upright.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/VF/SourceSans3VF-Upright.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/VF/SourceSans3VF-Upright.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/VF/SourceSans3VF-Upright.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-BlackIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-BlackIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-BoldIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-BoldIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-LightIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-LightIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-Medium.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-Medium.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-Regular.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-Regular.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-BlackIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-BlackIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-BoldIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-BoldIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-LightIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-LightIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-Medium.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-Medium.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-Regular.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-Regular.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/VF/SourceSans3VF-Italic.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/VF/SourceSans3VF-Italic.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/VF/SourceSans3VF-Italic.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/VF/SourceSans3VF-Italic.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-BlackIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-BlackIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-BoldIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-BoldIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-LightIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-LightIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-Regular.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-Regular.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-BlackIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-BlackIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-BoldIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-BoldIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-LightIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-LightIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-Regular.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-Regular.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-Black.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-Black.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-Bold.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-Bold.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-Light.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-Light.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-Black.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-Black.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-Bold.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-Bold.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-Light.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-Light.ttf.woff2 -------------------------------------------------------------------------------- /examples/second-lake/greeting/Main.lean: -------------------------------------------------------------------------------- 1 | import Greeting 2 | import Greeting.Smile 3 | 4 | open Expression 5 | 6 | def main : IO Unit := 7 | IO.println s!"Hello, {hello}, with {happy}!" 8 | -------------------------------------------------------------------------------- /book/static/fonts/noto-sans-mono/NotoSansMono-VariableFont_wdth,wght.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/noto-sans-mono/NotoSansMono-VariableFont_wdth,wght.ttf -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-Black.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-Black.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-Bold.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-Bold.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-BoldIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-BoldIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-Light.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-Light.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-Medium.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-Medium.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-Black.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-Black.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-Bold.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-Bold.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-BoldIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-BoldIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-Light.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-Light.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-Medium.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-Medium.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-Bold.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-It.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-It.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-It.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-It.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-ExtraLight.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-ExtraLight.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-ExtraLightIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-ExtraLightIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/OTF/SourceSans3-SemiboldIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/OTF/SourceSans3-SemiboldIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-ExtraLight.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-ExtraLight.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-ExtraLightIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-ExtraLightIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF/TTF/SourceSans3-SemiboldIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF/TTF/SourceSans3-SemiboldIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-ExtraLight.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-ExtraLight.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-MediumIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-MediumIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-Semibold.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-Semibold.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-SemiboldIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-SemiboldIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-ExtraLight.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-ExtraLight.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-MediumIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-MediumIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-Semibold.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-Semibold.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-SemiboldIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-SemiboldIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/VF/SourceSans3VF-Upright.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/VF/SourceSans3VF-Upright.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/VF/SourceSans3VF-Upright.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/VF/SourceSans3VF-Upright.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-ExtraLight.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-ExtraLight.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-Semibold.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-Semibold.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-SemiboldIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-SemiboldIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-ExtraLight.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-ExtraLight.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-Semibold.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-Semibold.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-SemiboldIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-SemiboldIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-BlackIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-BlackIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-BoldIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-BoldIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-LightIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-LightIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-Regular.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-Regular.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-Semibold.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-Semibold.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-BlackIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-BlackIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-BoldIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-BoldIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-LightIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-LightIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-Regular.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-Regular.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-Semibold.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-Semibold.ttf.woff2 -------------------------------------------------------------------------------- /examples/early-return/no-name: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect -f 2 | log_user 0 3 | spawn lean --run EarlyReturn.lean 4 | log_user 1 5 | 6 | expect "?" 7 | send "\n" 8 | expect "Hello, David!" 9 | 10 | -------------------------------------------------------------------------------- /examples/feline/2/lakefile.toml: -------------------------------------------------------------------------------- 1 | name = "feline" 2 | defaultTargets = ["feline"] 3 | 4 | [[lean_lib]] 5 | name = "FelineLib" 6 | 7 | [[lean_exe]] 8 | name = "feline" 9 | root = "Main" 10 | -------------------------------------------------------------------------------- /examples/hello-name/run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect -f 2 | log_user 0 3 | spawn lean --run HelloName.lean 4 | log_user 1 5 | 6 | expect "?" 7 | send "David\n" 8 | expect "Hello, David!" 9 | 10 | -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-BlackIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-BlackIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-LightIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-LightIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-MediumIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-MediumIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-Regular.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-Regular.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-Semibold.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-Semibold.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-BlackIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-BlackIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-LightIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-LightIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-MediumIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-MediumIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-Regular.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-Regular.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-Semibold.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-Semibold.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-Black.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-Black.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-BoldIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-BoldIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-Light.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-Light.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-Medium.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-Medium.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodeVF-Italic.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodeVF-Italic.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodeVF-Upright.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodeVF-Upright.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-Black.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-Black.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-BoldIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-BoldIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-Light.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-Light.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-Medium.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-Medium.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodeVF-Italic.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodeVF-Italic.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodeVF-Upright.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodeVF-Upright.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-ExtraLightIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/OTF/SourceSans3-ExtraLightIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-ExtraLightIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-sans/WOFF2/TTF/SourceSans3-ExtraLightIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-ExtraLightIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/OTF/SourceSerif4-ExtraLightIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-ExtraLightIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF/TTF/SourceSerif4-ExtraLightIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-ExtraLight.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-ExtraLight.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-SemiboldIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-SemiboldIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-ExtraLight.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-ExtraLight.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-SemiboldIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-SemiboldIt.ttf.woff2 -------------------------------------------------------------------------------- /examples/early-return/run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect -f 2 | log_user 0 3 | spawn lean --run EarlyReturn.lean 4 | log_user 1 5 | 6 | expect "?" 7 | send "David\n" 8 | expect "Hello, David!" 9 | 10 | -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-ExtraLight.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-ExtraLight.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-SemiboldIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-SemiboldIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-ExtraLight.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-ExtraLight.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-SemiboldIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-SemiboldIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-BlackIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-BlackIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-LightIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-LightIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-MediumIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-MediumIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-Regular.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-Semibold.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-Semibold.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-BlackIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-BlackIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-LightIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-LightIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-MediumIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-MediumIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-Semibold.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-Semibold.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-ExtraLightIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/OTF/SourceSerif4-ExtraLightIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-ExtraLightIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-serif/WOFF2/TTF/SourceSerif4-ExtraLightIt.ttf.woff2 -------------------------------------------------------------------------------- /examples/first-lake/expected/Greeting.lean: -------------------------------------------------------------------------------- 1 | -- This module serves as the root of the `Greeting` library. 2 | -- Import modules here that should be built as part of the library. 3 | import Greeting.Basic 4 | -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-ExtraLightIt.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/OTF/SourceCodePro-ExtraLightIt.otf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-ExtraLightIt.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF/TTF/SourceCodePro-ExtraLightIt.ttf.woff -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-ExtraLight.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-ExtraLight.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-SemiboldIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-SemiboldIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-ExtraLight.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-ExtraLight.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-SemiboldIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-SemiboldIt.ttf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-ExtraLightIt.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/OTF/SourceCodePro-ExtraLightIt.otf.woff2 -------------------------------------------------------------------------------- /book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-ExtraLightIt.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leanprover/fp-lean/HEAD/book/static/fonts/source-code-pro/WOFF2/TTF/SourceCodePro-ExtraLightIt.ttf.woff2 -------------------------------------------------------------------------------- /examples/inorder_python/expected: -------------------------------------------------------------------------------- 1 | Branch((3, 'd'), left=Branch((2, 'c'), left=Branch((0, 'a'), left=None, right=Branch((1, 'b'), left=None, right=None)), right=None), right=Branch((4, 'e'), left=None, right=None)) 2 | -------------------------------------------------------------------------------- /examples/first-lake/expected/lakefile.toml: -------------------------------------------------------------------------------- 1 | name = "greeting" 2 | version = "0.1.0" 3 | defaultTargets = ["greeting"] 4 | 5 | [[lean_lib]] 6 | name = "Greeting" 7 | 8 | [[lean_exe]] 9 | name = "greeting" 10 | root = "Main" 11 | -------------------------------------------------------------------------------- /examples/early-return/lakefile.lean: -------------------------------------------------------------------------------- 1 | import Lake 2 | open Lake DSL 3 | 4 | 5 | package «earlyreturn» { 6 | -- add package configuration options here 7 | } 8 | 9 | 10 | @[default_target] 11 | lean_exe «earlyreturn» { 12 | root := `EarlyReturn 13 | } 14 | -------------------------------------------------------------------------------- /book/.verso/verso-xref-manifest.json: -------------------------------------------------------------------------------- 1 | {"version": 0, 2 | "sources": 3 | {"manual": 4 | {"updated": "2025-10-23:16:40:12.244921000", 5 | "updateFrequency": "manual", 6 | "shortName": "ref", 7 | "root": "https://lean-lang.org/doc/reference/4.23.0/", 8 | "longName": "Lean Language Reference"}}, 9 | "outputDir": ".verso"} -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/technical-error.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Technical error 3 | about: Descriptions of technical mistakes in the content of the book 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Please quote the text that is incorrect: 11 | 12 | > MISTAKE GOES HERE 13 | 14 | In what way is this incorrect? 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/typo.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Typo 3 | about: Point out a typographical or grammatical error in the text 4 | title: "[Typo] " 5 | labels: Typo 6 | assignees: '' 7 | 8 | --- 9 | 10 | Please quote the complete incorrect sentence - this makes it easy to find in the source code of the book. 11 | 12 | Thank you! 13 | -------------------------------------------------------------------------------- /book/verso-sources.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 0, 3 | "sources": { 4 | "manual": { 5 | "root": "https://lean-lang.org/doc/reference/4.26.0/", 6 | "updateFrequency": "manual", 7 | "shortName": "ref", 8 | "longName": "Lean Language Reference" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/second-lake/greeting/lakefile.lean: -------------------------------------------------------------------------------- 1 | import Lake 2 | open Lake DSL 3 | 4 | require subverso from git "https://github.com/leanprover/subverso.git"@"main" 5 | 6 | 7 | package greeting { 8 | -- add package configuration options here 9 | } 10 | 11 | @[default_target] 12 | lean_lib Greeting 13 | 14 | @[default_target] 15 | lean_lib Aux 16 | 17 | @[default_target] 18 | lean_exe greeting { 19 | root := `Main 20 | } 21 | -------------------------------------------------------------------------------- /examples/Examples/ProgramsProofs/TCOTest.lean: -------------------------------------------------------------------------------- 1 | import Examples.ProgramsProofs.TCO 2 | 3 | def main : IO Unit := do 4 | let stdout ← IO.getStdout 5 | IO.println "Start" 6 | stdout.flush 7 | let theBigList := bigList 100000000 [] 8 | IO.println "One" 9 | stdout.flush 10 | IO.println theBigList.length 11 | IO.println (Tail.sum theBigList) 12 | -- IO.println "Two" 13 | -- stdout.flush 14 | -- IO.println (NonTail.sum theBigList) 15 | -------------------------------------------------------------------------------- /examples/lake-manifest.json: -------------------------------------------------------------------------------- 1 | {"version": "1.1.0", 2 | "packagesDir": ".lake/packages", 3 | "packages": 4 | [{"url": "https://github.com/leanprover/subverso.git", 5 | "type": "git", 6 | "subDir": null, 7 | "scope": "", 8 | "rev": "eb77622e97e942ba2cfe02f60637705fc2d9481b", 9 | "name": "subverso", 10 | "manifestFile": "lake-manifest.json", 11 | "inputRev": "main", 12 | "inherited": false, 13 | "configFile": "lakefile.lean"}], 14 | "name": "examples", 15 | "lakeDir": ".lake"} 16 | -------------------------------------------------------------------------------- /examples/second-lake/greeting/lake-manifest.json: -------------------------------------------------------------------------------- 1 | {"version": "1.1.0", 2 | "packagesDir": ".lake/packages", 3 | "packages": 4 | [{"url": "https://github.com/leanprover/subverso.git", 5 | "type": "git", 6 | "subDir": null, 7 | "scope": "", 8 | "rev": "bdc74c95376f9a5c23dba1b3159b03c5c1c8aad7", 9 | "name": "subverso", 10 | "manifestFile": "lake-manifest.json", 11 | "inputRev": "main", 12 | "inherited": false, 13 | "configFile": "lakefile.lean"}], 14 | "name": "greeting", 15 | "lakeDir": ".lake"} 16 | -------------------------------------------------------------------------------- /book/static/fonts/noto-sans-mono/noto-sans-mono.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Noto Sans Mono'; 3 | font-style: normal; 4 | font-display: swap; 5 | font-weight: 100 900; 6 | src: url('./NotoSansMono-VariableFont_wdth,wght.ttf') format('truetype'); 7 | unicode-range: U+207a-207F, U+208a-208f, U+2090-209c; 8 | } 9 | 10 | @font-face { 11 | font-family: 'Noto Sans Mono'; 12 | font-style: italic; 13 | font-display: swap; 14 | font-weight: 100 900; 15 | src: url('./NotoSansMono-VariableFont_wdth,wght.ttf') format('truetype'); 16 | unicode-range: U+207a-207F, U+208a-208f, U+2090-209c; 17 | } -------------------------------------------------------------------------------- /book/FPLean/Examples/Commands/Env.lean: -------------------------------------------------------------------------------- 1 | import Lean.Environment 2 | import Std.Data.HashMap 3 | import SubVerso.Highlighting.Highlighted 4 | import SubVerso.Module 5 | 6 | 7 | open Lean Std 8 | 9 | open SubVerso Highlighting Module Highlighted 10 | 11 | namespace FPLean 12 | 13 | structure Container where 14 | /-- The container's temporary working directory -/ 15 | workingDirectory : System.FilePath 16 | /-- The saved outputs from each command run in the container -/ 17 | outputs : HashMap String String := {} 18 | 19 | initialize containersExt : (EnvExtension (NameMap Container)) ← registerEnvExtension (pure {}) 20 | -------------------------------------------------------------------------------- /examples/ForMIO.lean: -------------------------------------------------------------------------------- 1 | -- ANCHOR: LinesOf 2 | structure LinesOf where 3 | stream : IO.FS.Stream 4 | 5 | partial def LinesOf.forM 6 | (readFrom : LinesOf) (action : String → IO Unit) : 7 | IO Unit := do 8 | let line ← readFrom.stream.getLine 9 | if line == "" then return () 10 | action line 11 | forM readFrom action 12 | 13 | instance : ForM IO LinesOf String where 14 | forM := LinesOf.forM 15 | -- ANCHOR_END: LinesOf 16 | 17 | -- ANCHOR: main 18 | def main (argv : List String) : IO UInt32 := do 19 | if argv != [] then 20 | IO.eprintln "Unexpected arguments" 21 | return 1 22 | 23 | forM (LinesOf.mk (← IO.getStdin)) fun line => do 24 | if line.any (·.isAlpha) then 25 | IO.print line 26 | 27 | return 0 28 | -- ANCHOR_END: main 29 | -------------------------------------------------------------------------------- /book/static/fonts/source-sans/source-sans-3VF.css: -------------------------------------------------------------------------------- 1 | @font-face{ 2 | font-family: 'Source Sans 3 VF'; 3 | font-weight: 200 900; 4 | font-style: normal; 5 | font-stretch: normal; 6 | src: url('WOFF2/VF/SourceSans3VF-Upright.ttf.woff2') format('woff2-variations'), 7 | url('WOFF/VF/SourceSans3VF-Upright.ttf.woff') format('woff-variations'), 8 | url('VF/SourceSans3VF-Upright.ttf') format('truetype-variations'); 9 | } 10 | 11 | @font-face{ 12 | font-family: 'Source Sans 3 VF'; 13 | font-weight: 200 900; 14 | font-style: italic; 15 | font-stretch: normal; 16 | src: url('WOFF2/VF/SourceSans3VF-Italic.ttf.woff2') format('woff2-variations'), 17 | url('WOFF/VF/SourceSans3VF-Italic.ttf.woff') format('woff-variations'), 18 | url('VF/SourceSans3VF-Italic.ttf') format('truetype-variations'); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Examples/SpecialTypes.lean: -------------------------------------------------------------------------------- 1 | -- ANCHOR: all 2 | example := List 3 | example := [UInt8, UInt16, UInt32, UInt64, USize, Int8, Int16, Int32, Int64, ISize] 4 | example := Fin (2 ^ 32) 5 | example := [Nat, List Unit, String, Int, Char, List Char] 6 | example {w} := BitVec w 7 | example := [true, false] 8 | example {x : α} := [some x, none] 9 | example := ∀ {n k : Nat}, n ≠ 0 → k ≠ 0 → n + k ≠ 0 10 | example := [Add, Mul, ToString] 11 | example := Nat.succ 12 | section 13 | universe u 14 | example := Sort u 15 | end 16 | -- ANCHOR_END: all 17 | 18 | -- ANCHOR: sequences 19 | section 20 | example {α} := [List α, Array α] 21 | open Array 22 | example : Array α → List α := toList 23 | end 24 | -- ANCHOR_END: sequences 25 | 26 | -- ANCHOR: StringDetail 27 | section 28 | open String 29 | example : String → List Char := data 30 | end 31 | -- ANCHOR_END: StringDetail 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Functional Programming in Lean 2 | 3 | This repository contains the source code of the book Functional Programming in Lean by David Thrane Christiansen. 4 | 5 | The original version of the book was released by Microsoft Corporation in 2023 under a Creative Commons Attribution 4.0 International License. The current version has been modified by the author from the original version to account for changes in newer versions of Lean and to use Verso; these changes are copyright 2023-2025 Lean FRO, LLC. A detailed account of the changes can be found in the book's [source code repository](https://github.com/leanprover/fp-lean/). 6 | 7 | 8 | The book's build has been tested with: 9 | 10 | 1. Lean 4 (see the version in lean-toolchain in examples/) 11 | 2. expect (tested with v5.45.4 but any version from the last decade should work) 12 | 13 | To build the book, change to the "book" directory and run "lake exe fp-lean". After this, "book/out/html-multi" contains a multi-page Web version of the book. 14 | 15 | -------------------------------------------------------------------------------- /examples/inorder_python/inordernumbering.py: -------------------------------------------------------------------------------- 1 | 2 | # ANCHOR: code 3 | class Branch: 4 | def __init__(self, value, left=None, right=None): 5 | self.left = left 6 | self.value = value 7 | self.right = right 8 | def __repr__(self): 9 | return f'Branch({self.value!r}, left={self.left!r}, right={self.right!r})' 10 | 11 | def number(tree): 12 | num = 0 13 | def helper(t): 14 | nonlocal num 15 | if t is None: 16 | return None 17 | else: 18 | new_left = helper(t.left) 19 | new_value = (num, t.value) 20 | num += 1 21 | new_right = helper(t.right) 22 | return Branch(left=new_left, value=new_value, right=new_right) 23 | 24 | return helper(tree) 25 | # ANCHOR_END: code 26 | 27 | # ANCHOR: a_tree 28 | a_tree = Branch("d", 29 | left=Branch("c", 30 | left=Branch("a", left=None, right=Branch("b")), 31 | right=None), 32 | right=Branch("e")) 33 | # ANCHOR_END: a_tree 34 | 35 | print(number(a_tree)) 36 | -------------------------------------------------------------------------------- /book/Main.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | import FPLean 3 | 4 | open Verso.Genre Manual 5 | open Verso Code External 6 | 7 | open Verso.Output.Html in 8 | def plausible := {{ 9 | 10 | }} 11 | 12 | 13 | def config : Config where 14 | emitTeX := false 15 | emitHtmlSingle := false 16 | emitHtmlMulti := true 17 | htmlDepth := 2 18 | extraFiles := [("static", "static")] 19 | extraCss := [ 20 | "/static/theme.css", 21 | "/static/fonts/source-serif/source-serif-text.css", 22 | "/static/fonts/source-code-pro/source-code-pro.css", 23 | "/static/fonts/source-sans/source-sans-3.css", 24 | "/static/fonts/noto-sans-mono/noto-sans-mono.css" 25 | ] 26 | extraHead := #[plausible] 27 | logo := some "/static/lean_logo.svg" 28 | sourceLink := some "https://github.com/leanprover/fp-lean" 29 | issueLink := some "https://github.com/leanprover/fp-lean/issues" 30 | linkTargets := fun st => st.localTargets ++ st.remoteTargets 31 | def main := manualMain (%doc FPLean) (config := config.addKaTeX) 32 | -------------------------------------------------------------------------------- /examples/Examples.lean: -------------------------------------------------------------------------------- 1 | import Examples.Intro 2 | import Examples.HelloWorld 3 | import Examples.Cat 4 | import Examples.Props 5 | import Examples.Classes 6 | import Examples.Classes.Even 7 | import Examples.Induction 8 | import Examples.Monads 9 | import Examples.Monads.Class 10 | import Examples.Monads.Many 11 | import Examples.Monads.Do 12 | import Examples.Monads.IO 13 | import Examples.Monads.Conveniences 14 | import Examples.FunctorApplicativeMonad 15 | import Examples.Universes 16 | import Examples.FunctorApplicativeMonad.ActualDefs 17 | import Examples.MonadTransformers 18 | import Examples.MonadTransformers.Defs 19 | import Examples.MonadTransformers.Conveniences 20 | import Examples.DependentTypes 21 | import Examples.DependentTypes.DB 22 | import Examples.DependentTypes.IndicesParameters 23 | import Examples.DependentTypes.Pitfalls 24 | import Examples.ProgramsProofs.TCO 25 | import Examples.ProgramsProofs.Arrays 26 | import Examples.ProgramsProofs.Fin 27 | import Examples.ProgramsProofs.InsertionSort 28 | import Examples.ProgramsProofs.Inequalities 29 | 30 | 31 | def whatIsThis : String := "This is a place for examples for the book." 32 | -------------------------------------------------------------------------------- /examples/early-return/EarlyReturn.lean: -------------------------------------------------------------------------------- 1 | -- ANCHOR: main 2 | def main (argv : List String) : IO UInt32 := do 3 | let stdin ← IO.getStdin 4 | let stdout ← IO.getStdout 5 | let stderr ← IO.getStderr 6 | 7 | unless argv == [] do 8 | stderr.putStrLn s!"Expected no arguments, but got {argv.length}" 9 | return 1 10 | 11 | stdout.putStrLn "How would you like to be addressed?" 12 | stdout.flush 13 | 14 | let name := (← stdin.getLine).trim 15 | if name == "" then 16 | stderr.putStrLn s!"No name provided" 17 | return 1 18 | 19 | stdout.putStrLn s!"Hello, {name}!" 20 | 21 | return 0 22 | -- ANCHOR_END: main 23 | 24 | namespace Nested 25 | -- ANCHOR: nestedmain 26 | def main (argv : List String) : IO UInt32 := do 27 | let stdin ← IO.getStdin 28 | let stdout ← IO.getStdout 29 | let stderr ← IO.getStderr 30 | 31 | if argv != [] then 32 | stderr.putStrLn s!"Expected no arguments, but got {argv.length}" 33 | pure 1 34 | else 35 | stdout.putStrLn "How would you like to be addressed?" 36 | stdout.flush 37 | 38 | let name := (← stdin.getLine).trim 39 | if name == "" then 40 | stderr.putStrLn s!"No name provided" 41 | pure 1 42 | else 43 | stdout.putStrLn s!"Hello, {name}!" 44 | pure 0 45 | -- ANCHOR_END: nestedmain 46 | end Nested 47 | 48 | theorem mains_match : main = Nested.main := by 49 | funext argv 50 | simp [main, Nested.main] 51 | congr 52 | -------------------------------------------------------------------------------- /examples/lakefile.lean: -------------------------------------------------------------------------------- 1 | import Lake 2 | open Lake DSL 3 | 4 | require subverso from git "https://github.com/leanprover/subverso.git"@"main" 5 | 6 | package examples { 7 | -- add configuration options here 8 | } 9 | 10 | @[default_target] 11 | lean_lib SimpleHello where 12 | srcDir := "simple-hello" 13 | roots := #[`Hello] 14 | 15 | @[default_target] 16 | lean_lib HelloName where 17 | srcDir := "hello-name" 18 | roots := #[`HelloName] 19 | 20 | @[default_target] 21 | lean_lib ExampleSupport 22 | 23 | @[default_target] 24 | lean_lib Examples 25 | 26 | @[default_target] 27 | lean_lib FelineLib { 28 | srcDir := "feline/2" 29 | roots := #[`FelineLib] 30 | } 31 | 32 | @[default_target] 33 | lean_lib EarlyReturn where 34 | srcDir := "early-return" 35 | 36 | @[default_target] 37 | lean_exe ForMIO where 38 | 39 | 40 | @[default_target] 41 | lean_exe feline { 42 | srcDir := "feline/2" 43 | root := `Main 44 | } 45 | 46 | @[default_target] 47 | lean_exe examples { 48 | root := `Main 49 | } 50 | 51 | @[default_target] 52 | lean_exe countdown { 53 | root := `Examples.HelloWorld 54 | } 55 | 56 | @[default_target] 57 | lean_lib DougLib where 58 | srcDir := "douglib" 59 | roots := #[`DirTree] 60 | 61 | @[default_target] 62 | lean_exe doug { 63 | root := `Examples.Doug1 64 | } 65 | 66 | @[default_target] 67 | lean_exe tco { 68 | root := `Examples.ProgramsProofs.TCOTest 69 | } 70 | 71 | @[default_target] 72 | lean_exe sort { 73 | root := `Examples.ProgramsProofs.InstrumentedInsertionSort 74 | } 75 | -------------------------------------------------------------------------------- /book/lake-manifest.json: -------------------------------------------------------------------------------- 1 | {"version": "1.1.0", 2 | "packagesDir": ".lake/packages", 3 | "packages": 4 | [{"url": "https://github.com/leanprover/verso.git", 5 | "type": "git", 6 | "subDir": null, 7 | "scope": "", 8 | "rev": "ea44a4d919a4570055bf53171ea4d8a8919cde84", 9 | "name": "verso", 10 | "manifestFile": "lake-manifest.json", 11 | "inputRev": "main", 12 | "inherited": false, 13 | "configFile": "lakefile.lean"}, 14 | {"url": "https://github.com/leanprover-community/plausible", 15 | "type": "git", 16 | "subDir": null, 17 | "scope": "", 18 | "rev": "160af9e8e7d4ae448f3c92edcc5b6a8522453f11", 19 | "name": "plausible", 20 | "manifestFile": "lake-manifest.json", 21 | "inputRev": "main", 22 | "inherited": true, 23 | "configFile": "lakefile.toml"}, 24 | {"url": "https://github.com/acmepjz/md4lean", 25 | "type": "git", 26 | "subDir": null, 27 | "scope": "", 28 | "rev": "38ac5945d744903ffcc473ce1030223991b11cf6", 29 | "name": "MD4Lean", 30 | "manifestFile": "lake-manifest.json", 31 | "inputRev": "main", 32 | "inherited": true, 33 | "configFile": "lakefile.lean"}, 34 | {"url": "https://github.com/leanprover/subverso", 35 | "type": "git", 36 | "subDir": null, 37 | "scope": "", 38 | "rev": "eb77622e97e942ba2cfe02f60637705fc2d9481b", 39 | "name": "subverso", 40 | "manifestFile": "lake-manifest.json", 41 | "inputRev": "main", 42 | "inherited": true, 43 | "configFile": "lakefile.lean"}], 44 | "name": "book", 45 | "lakeDir": ".lake"} 46 | -------------------------------------------------------------------------------- /examples/Examples/ProgramsProofs/Div.lean: -------------------------------------------------------------------------------- 1 | import ExampleSupport 2 | 3 | discarding 4 | /-- 5 | error: fail to show termination for 6 | div 7 | with errors 8 | failed to infer structural recursion: 9 | Not considering parameter k of div: 10 | it is unchanged in the recursive calls 11 | Cannot use parameter k: 12 | failed to eliminate recursive application 13 | div (n - k) k 14 | 15 | 16 | failed to prove termination, possible solutions: 17 | - Use `have`-expressions to prove the remaining goals 18 | - Use `termination_by` to specify a different well-founded relation 19 | - Use `decreasing_by` to specify your own tactic for discharging this kind of goal 20 | k n : Nat 21 | h✝ : ¬n < k 22 | ⊢ n - k < n 23 | -/ 24 | #check_msgs in 25 | -- ANCHOR: divTermination 26 | def div (n k : Nat) : Nat := 27 | if n < k then 28 | 0 29 | else 30 | 1 + div (n - k) k 31 | -- ANCHOR_END: divTermination 32 | stop discarding 33 | 34 | discarding 35 | -- ANCHOR: divRecursiveNeedsProof 36 | def div (n k : Nat) (ok : k ≠ 0) : Nat := 37 | if h : n < k then 38 | 0 39 | else 40 | 1 + div (n - k) k ok 41 | -- ANCHOR_END: divRecursiveNeedsProof 42 | stop discarding 43 | 44 | -- ANCHOR: divRecursiveWithProof 45 | def div (n k : Nat) (ok : k ≠ 0) : Nat := 46 | if h : n < k then 47 | 0 48 | else 49 | 1 + div (n - k) k ok 50 | termination_by n 51 | -- ANCHOR_END: divRecursiveWithProof 52 | 53 | 54 | -- ANCHOR: NatSubLt 55 | example : ∀ {n k : Nat}, 0 < n → 0 < k → n - k < n := @Nat.sub_lt 56 | -- ANCHOR_END: NatSubLt 57 | 58 | 59 | #eval div 13 2 (by simp) 60 | -------------------------------------------------------------------------------- /book/static/theme.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --verso-structure-font-family: "Source Sans 3","Helvetica Neue","Segoe UI","Roboto",Arial,sans-serif; 3 | --verso-text-font-family: "Source Sans 3","Helvetica Neue","Segoe UI","Roboto",Arial,sans-serif; 4 | --verso-code-font-family: "Source Code Pro","Noto Sans Mono",monospace; 5 | --verso-selected-color: #def; 6 | } 7 | 8 | .eval-steps > *:not(:last-child):after { 9 | content: "⇒"; 10 | display: block; 11 | padding-left: 1rem; 12 | font-size: 150%; 13 | } 14 | 15 | 16 | .hl.lean .keyword.token { 17 | font-weight: 600 !important; 18 | } 19 | 20 | 21 | .error pre, .information pre, .warning pre, 22 | .error code, .information code, .warning code { 23 | overflow-x: auto; 24 | margin: 0px; 25 | } 26 | 27 | .information pre, .error pre, .warning pre, 28 | .information code, .error code, .warning code { 29 | margin: 0.5em .85em; 30 | border-left: 0.2em solid red; 31 | padding: 0 0.45em; 32 | } 33 | 34 | /* Different color for warning */ 35 | .warning pre, .warning code { 36 | border-color: var(--verso-warning-color); 37 | } 38 | 39 | /* Different color for information */ 40 | .information pre, .information code { 41 | border-color: #0000c0; 42 | } 43 | 44 | /* TODO: fix upstream */ 45 | .hl.lean code { 46 | font-family: var(--verso-code-font-family) !important; 47 | } 48 | 49 | 50 | #toc .split-toc > ol > li { 51 | margin-bottom: 0.2rem; 52 | } 53 | 54 | #toc .split-toc > ol .tactic-name { 55 | font-weight: 600; 56 | } 57 | 58 | .def-technical-term:target { 59 | background-color: var(--verso-selected-color); 60 | outline: auto; 61 | } 62 | 63 | /********/ 64 | 65 | p { 66 | font-feature-settings: "calt" off; 67 | } 68 | -------------------------------------------------------------------------------- /book/FPLean/HelloWorld.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | import FPLean.Examples 3 | 4 | import FPLean.HelloWorld.RunningAProgram 5 | import FPLean.HelloWorld.StepByStep 6 | import FPLean.HelloWorld.StartingAProject 7 | import FPLean.HelloWorld.Cat 8 | import FPLean.HelloWorld.Conveniences 9 | import FPLean.HelloWorld.Summary 10 | 11 | 12 | open Verso.Genre Manual 13 | open Verso Code External 14 | 15 | open FPLean 16 | 17 | 18 | #doc (Manual) "Hello, World!" => 19 | %%% 20 | tag := "hello-world" 21 | %%% 22 | 23 | While Lean has been designed to have a rich interactive environment in which programmers can get quite a lot of feedback from the language without leaving the confines of their favorite text editor, it is also a language in which real programs can be written. 24 | This means that it also has a batch-mode compiler, a build system, a package manager, and all the other tools that are necessary for writing programs. 25 | 26 | While the {ref "getting-to-know"}[previous chapter] presented the basics of functional programming in Lean, this chapter explains how to start a programming project, compile it, and run the result. 27 | Programs that run and interact with their environment (e.g. by reading input from standard input or creating files) are difficult to reconcile with the understanding of computation as the evaluation of mathematical expressions. 28 | In addition to a description of the Lean build tools, this chapter also provides a way to think about functional programs that interact with the world. 29 | 30 | {include 1 FPLean.HelloWorld.RunningAProgram} 31 | 32 | {include 1 FPLean.HelloWorld.StepByStep} 33 | 34 | {include 1 FPLean.HelloWorld.StartingAProject} 35 | 36 | {include 1 FPLean.HelloWorld.Cat} 37 | 38 | {include 1 FPLean.HelloWorld.Conveniences} 39 | 40 | {include 1 FPLean.HelloWorld.Summary} 41 | -------------------------------------------------------------------------------- /book/FPLean.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | 3 | import FPLean.Intro 4 | import FPLean.Acks 5 | import FPLean.GettingToKnow 6 | import FPLean.HelloWorld 7 | import FPLean.PropsProofsIndexing 8 | import FPLean.TypeClasses 9 | import FPLean.Monads 10 | import FPLean.FunctorApplicativeMonad 11 | import FPLean.MonadTransformers 12 | import FPLean.DependentTypes 13 | import FPLean.TacticsInductionProofs 14 | import FPLean.ProgramsProofs 15 | import FPLean.NextSteps 16 | 17 | open Verso.Genre Manual 18 | open Verso Code External 19 | 20 | open Verso Doc Elab in 21 | open Lean (quote) in 22 | @[role_expander versionString] 23 | def versionString : RoleExpander 24 | | #[], #[] => do 25 | let version ← IO.FS.readFile "../examples/lean-toolchain" 26 | let version := version.stripPrefix "leanprover/lean4:" |>.trim 27 | pure #[← ``(Verso.Doc.Inline.code $(quote version))] 28 | | _, _ => throwError "Unexpected arguments" 29 | 30 | 31 | #doc (Manual) "Functional Programming in Lean" => 32 | 33 | %%% 34 | authors := ["David Thrane Christiansen"] 35 | %%% 36 | 37 | 38 | _Copyright Microsoft Corporation 2023 and Lean FRO, LLC 2023–2025_ 39 | 40 | 41 | 42 | This is a free book on using Lean as a programming language. All code samples are tested with Lean release {versionString}[]. 43 | 44 | {include 1 FPLean.Intro} 45 | 46 | {include 1 FPLean.Acks} 47 | 48 | {include 1 FPLean.GettingToKnow} 49 | 50 | {include 1 FPLean.HelloWorld} 51 | 52 | {include 1 FPLean.PropsProofsIndexing} 53 | 54 | {include 1 FPLean.TypeClasses} 55 | 56 | {include 1 FPLean.Monads} 57 | 58 | {include 1 FPLean.FunctorApplicativeMonad} 59 | 60 | {include 1 FPLean.MonadTransformers} 61 | 62 | {include 1 FPLean.DependentTypes} 63 | 64 | {include 1 FPLean.TacticsInductionProofs} 65 | 66 | {include 1 FPLean.ProgramsProofs} 67 | 68 | {include 1 FPLean.NextSteps} 69 | -------------------------------------------------------------------------------- /examples/hello-name/HelloName.lean: -------------------------------------------------------------------------------- 1 | -- ANCHOR: all 2 | -- ANCHOR: sig 3 | def main : IO Unit := do 4 | -- ANCHOR_END: sig 5 | -- ANCHOR: setup 6 | let stdin ← IO.getStdin 7 | let stdout ← IO.getStdout 8 | -- ANCHOR_END: setup 9 | 10 | -- ANCHOR: question 11 | stdout.putStrLn "How would you like to be addressed?" 12 | let input ← stdin.getLine 13 | let name := input.dropRightWhile Char.isWhitespace 14 | -- ANCHOR_END: question 15 | 16 | -- ANCHOR: answer 17 | stdout.putStrLn s!"Hello, {name}!" 18 | -- ANCHOR_END: answer 19 | -- ANCHOR_END: all 20 | 21 | 22 | def mainSplit : IO Unit := do 23 | -- ANCHOR: block1 24 | -- ANCHOR: line1 25 | let stdin ← IO.getStdin 26 | -- ANCHOR_END: line1 27 | -- ANCHOR: block2 28 | -- ANCHOR: line2 29 | let stdout ← IO.getStdout 30 | -- ANCHOR_END: line2 31 | -- ANCHOR: block3 32 | -- ANCHOR: line3 33 | stdout.putStrLn "How would you like to be addressed?" 34 | -- ANCHOR_END: line3 35 | -- ANCHOR: block4 36 | -- ANCHOR: line4 37 | let input ← stdin.getLine 38 | -- ANCHOR_END: line4 39 | -- ANCHOR: block5 40 | -- ANCHOR: line5 41 | let name := input.dropRightWhile Char.isWhitespace 42 | -- ANCHOR_END: line5 43 | -- ANCHOR: block6 44 | -- ANCHOR: line6 45 | stdout.putStrLn s!"Hello, {name}!" 46 | -- ANCHOR_END: line6 47 | -- ANCHOR_END: block6 48 | -- ANCHOR_END: block5 49 | -- ANCHOR_END: block4 50 | -- ANCHOR_END: block3 51 | -- ANCHOR_END: block2 52 | -- ANCHOR_END: block1 53 | 54 | -- Keep checking that they're identical 55 | example : main = mainSplit := by rfl 56 | 57 | example := String.dropRightWhile 58 | example {α : Type} := IO α 59 | example : String → IO Unit := IO.println 60 | example := Bool 61 | open Unit in 62 | example : Unit := unit 63 | example := IO.FS.Stream 64 | example : IO.FS.Stream → String → IO Unit := IO.FS.Stream.putStrLn 65 | example : IO.FS.Stream → IO String := IO.FS.Stream.getLine 66 | -------------------------------------------------------------------------------- /examples/Examples/MonadTransformers.lean: -------------------------------------------------------------------------------- 1 | import ExampleSupport 2 | import Examples.Monads 3 | 4 | namespace Evaluator 5 | 6 | inductive Prim where 7 | | plus 8 | | minus 9 | | times 10 | | div 11 | 12 | def Var := String 13 | 14 | deriving instance BEq, ToString for Var 15 | 16 | inductive Expr where 17 | | var : Var → Expr 18 | | prim : Prim → Expr → Expr → Expr 19 | | const : Int → Expr 20 | | lett : Var → Expr → Expr → Expr 21 | 22 | abbrev Env := List (Var × Int) 23 | 24 | def Eval (α : Type) : Type := 25 | Env → Except String α 26 | 27 | instance : Monad Eval where 28 | pure x := fun _ => .ok x 29 | bind m f := fun ρ => 30 | match m ρ with 31 | | .error e => .error e 32 | | .ok x => f x ρ 33 | 34 | def currentEnv : Eval Env := fun ρ => .ok ρ 35 | 36 | def bind (x : Var) (v : Int) (during : Eval α) : Eval α := 37 | fun ρ => 38 | during ((x, v) :: ρ) 39 | 40 | def crash (msg : String) : Eval α := 41 | fun _ => .error msg 42 | 43 | def lookup (x : Var) : Eval Int := do 44 | let ρ ← currentEnv 45 | match ρ.lookup x with 46 | | none => crash s!"Unknown variable {x}" 47 | | some i => pure i 48 | 49 | def applyPrim (op : Prim) (v1 v2 : Int) : Eval Int := 50 | match op with 51 | | .plus => pure (v1 + v2) 52 | | .minus => pure (v1 - v2) 53 | | .times => pure (v1 * v2) 54 | | .div => 55 | if v2 == 0 then 56 | crash s!"Attempted to divide {v1} by 0" 57 | else 58 | pure (v1 + v2) 59 | 60 | def evaluate : Expr → Eval Int 61 | | .var x => lookup x 62 | | .prim op e1 e2 => do 63 | let v1 ← evaluate e1 64 | let v2 ← evaluate e2 65 | applyPrim op v1 v2 66 | | .const i => pure i 67 | | .lett x e1 e2 => do 68 | let v1 ← evaluate e1 69 | bind x v1 (evaluate e2) 70 | 71 | end Evaluator 72 | 73 | -- ANCHOR: Summary 74 | example := Monad 75 | example := MonadLift 76 | example := StateT 77 | example := ExceptT 78 | example := Unit 79 | -- ANCHOR_END: Summary 80 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | This project is a single-author text. Generally speaking, I'm not interested in pull requests that modify the text of the online book, because I want to maintain a single coherent authorial voice and style for readers. Additionally, the book is now considered to be complete. It may receive updates to keep it up to date with changes in Lean 4 over time, or to fix errors, but I do not expect to add significant amounts of new content. 4 | 5 | ## Mistakes 6 | 7 | If you find a mistake in the book, please open an issue! I'd like this book to be a correct and reliable resource, and to stay that way over time. 8 | 9 | Please don't open issues for questions about Lean or solving exercises. These discussions are better suited to the [Lean Zulip](https://leanprover.zulipchat.com/). 10 | 11 | ## Book Infrastructure 12 | 13 | The infrastructure of the book, like the Lean metaprograms in `Examples.Support` and the Python scripts that extract examples into the text, is currently "good enough". This means that the code is not as elegant as it could be, but it's sufficient to accomplish its task. If you re-use this code in your own book project and find bugs, then I'd like to fix them here too, but I'm not generally interested in stylistic improvements. 14 | 15 | The code exists to create the rendered HTML version of the book, primarily when running on GitHub Actions and secondarily on Unix-like systems such as WSL, Linux, or macOS. I'm not interested in generalizations to other platforms or contexts because I don't have the time and expertise to maintain them. 16 | 17 | ## Pull Requests 18 | 19 | Generally speaking, pull requests are not welcome without prior agreement. Should you wish to contribute a pull request, you'll need to [sign a CLA](https://cla.opensource.microsoft.com/) with Microsoft. Please contact Sarah Smith (smithsarah@microsoft.com) or Gabriel Ebner (gabrielebner@microsoft.com) if you have any questions about this. 20 | -------------------------------------------------------------------------------- /examples/feline/2/FelineLib.lean: -------------------------------------------------------------------------------- 1 | -- ANCHOR: bufsize 2 | def bufsize : USize := 20 * 1024 3 | -- ANCHOR_END: bufsize 4 | 5 | -- ANCHOR: dump 6 | partial def dump (stream : IO.FS.Stream) : IO Unit := do 7 | let buf ← stream.read bufsize 8 | if buf.isEmpty then 9 | pure () 10 | else 11 | -- ANCHOR: stdoutBind 12 | let stdout ← IO.getStdout 13 | stdout.write buf 14 | -- ANCHOR_END: stdoutBind 15 | dump stream 16 | -- ANCHOR_END: dump 17 | 18 | -- ANCHOR: fileStream 19 | def fileStream (filename : System.FilePath) : IO (Option IO.FS.Stream) := do 20 | -- ANCHOR: fileExistsBind 21 | let fileExists ← filename.pathExists 22 | if not fileExists then 23 | -- ANCHOR_END: fileExistsBind 24 | let stderr ← IO.getStderr 25 | stderr.putStrLn s!"File not found: {filename}" 26 | pure none 27 | else 28 | let handle ← IO.FS.Handle.mk filename IO.FS.Mode.read 29 | pure (some (IO.FS.Stream.ofHandle handle)) 30 | -- ANCHOR_END: fileStream 31 | 32 | -- ANCHOR: Names 33 | section 34 | open IO.FS 35 | #check Stream 36 | open System 37 | #check FilePath 38 | 39 | namespace Main1 40 | def main : IO Unit := pure () 41 | end Main1 42 | namespace Main2 43 | def main : IO UInt32 := pure 0 44 | end Main2 45 | namespace Main3 46 | def main : List String → IO UInt32 := fun _ => pure 0 47 | end Main3 48 | 49 | end 50 | -- ANCHOR_END: Names 51 | 52 | -- ANCHOR: process 53 | def process (exitCode : UInt32) (args : List String) : IO UInt32 := do 54 | match args with 55 | | [] => pure exitCode 56 | | "-" :: args => 57 | let stdin ← IO.getStdin 58 | dump stdin 59 | process exitCode args 60 | | filename :: args => 61 | let stream ← fileStream ⟨filename⟩ 62 | match stream with 63 | | none => 64 | process 1 args 65 | | some stream => 66 | dump stream 67 | process exitCode args 68 | -- ANCHOR_END: process 69 | 70 | -- ANCHOR: main 71 | def main (args : List String) : IO UInt32 := 72 | match args with 73 | | [] => process 0 ["-"] 74 | | _ => process 0 args 75 | -- ANCHOR_END: main 76 | 77 | example := USize 78 | -------------------------------------------------------------------------------- /book/FPLean/MonadTransformers.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | 3 | import FPLean.Examples 4 | 5 | import FPLean.MonadTransformers.ReaderIO 6 | import FPLean.MonadTransformers.Transformers 7 | import FPLean.MonadTransformers.Order 8 | import FPLean.MonadTransformers.Do 9 | import FPLean.MonadTransformers.Conveniences 10 | import FPLean.MonadTransformers.Summary 11 | 12 | open Verso.Genre Manual 13 | open Verso Code External 14 | 15 | open FPLean 16 | 17 | 18 | set_option verso.exampleProject "../examples" 19 | set_option verso.exampleModule "Examples.Monads" 20 | 21 | #doc (Manual) "Monad Transformers" => 22 | 23 | A monad is a way to encode some collection of side effects in a pure language. 24 | Different monads provide different effects, such as state and error handling. 25 | Many monads even provide useful effects that aren't available in most languages, such as nondeterministic searches, readers, and even continuations. 26 | 27 | A typical application has a core set of easily testable functions written without monads paired with an outer wrapper that uses a monad to encode the necessary application logic. 28 | These monads are constructed from well-known components. 29 | For example: 30 | * Mutable state is encoded with a function parameter and a return value that have the same type 31 | * Error handling is encoded by having a return type that is similar to {moduleName}`Except`, with constructors for success and failure 32 | * Logging is encoded by pairing the return value with the log 33 | 34 | Writing each monad by hand is tedious, however, involving boilerplate definitions of the various type classes. 35 | Each of these components can also be extracted to a definition that modifies some other monad to add an additional effect. 36 | Such a definition is called a _monad transformer_. 37 | A concrete monad can be build from a collection of monad transformers, which enables much more code re-use. 38 | 39 | {include 1 FPLean.MonadTransformers.ReaderIO} 40 | 41 | {include 1 FPLean.MonadTransformers.Transformers} 42 | 43 | {include 1 FPLean.MonadTransformers.Order} 44 | 45 | {include 1 FPLean.MonadTransformers.Do} 46 | 47 | {include 1 FPLean.MonadTransformers.Conveniences} 48 | 49 | {include 1 FPLean.MonadTransformers.Summary} 50 | -------------------------------------------------------------------------------- /book/FPLean/Acks.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | import FPLean.Examples 3 | 4 | open Verso.Genre Manual 5 | open Verso.Code.External 6 | 7 | open FPLean 8 | 9 | set_option verso.exampleProject "../examples" 10 | set_option verso.exampleModule "Examples.TODO" 11 | 12 | #doc (Manual) "Acknowledgments" => 13 | %%% 14 | number := false 15 | %%% 16 | 17 | 18 | This free online book was made possible by the generous support of Microsoft Research, who paid for it to be written and given away. 19 | During the process of writing, they made the expertise of the Lean development team available to both answer my questions and make Lean easier to use. 20 | In particular, Leonardo de Moura initiated the project and helped me get started, Chris Lovett set up the CI and deployment automation and provided great feedback as a test reader, Gabriel Ebner provided technical reviews, Sarah Smith kept the administrative side working well, and Vanessa Rodriguez helped me diagnose a tricky interaction between the source-code highlighting library and certain versions of Safari on iOS. 21 | 22 | Writing this book has taken up many hours outside of normal working hours. 23 | My wife Ellie Thrane Christiansen has taken on a larger than usual share of running the family, and this book could not exist if she had not done so. 24 | An extra day of work each week has not been easy for my family—thank you for your patience and support while I was writing. 25 | 26 | The online community surrounding Lean provided enthusiastic support for the project, both technical and emotional. 27 | In particular, Sebastian Ullrich provided key help when I was learning Lean's metaprogramming system in order to write the supporting code that allowed the text of error messages to be both checked in CI and easily included in the book itself. 28 | Within hours of posting a new revision, excited readers would be finding mistakes, providing suggestions, and showering me with kindness. 29 | In particular, I'd like to thank Arien Malec, Asta Halkjær From, Bulhwi Cha, Craig Stuntz, Daniel Fabian, Evgenia Karunus, eyelash, Floris van Doorn, František Silváši, Henrik Böving, Ian Young, Jeremy Salwen, Jireh Loreaux, Kevin Buzzard, Lars Ericson, Liu Yuxi, Mac Malone, Malcolm Langfield, Mario Carneiro, Newell Jensen, Patrick Massot, Paul Chisholm, Pietro Monticone, Tomas Puverle, Yaël Dillies, Zhiyuan Bao, and Zyad Hassan for their many suggestions, both stylistic and technical. 30 | -------------------------------------------------------------------------------- /book/FPLean/GettingToKnow.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | import FPLean.Examples 3 | import FPLean.GettingToKnow.Evaluating 4 | import FPLean.GettingToKnow.Types 5 | import FPLean.GettingToKnow.FunctionsDefinitions 6 | import FPLean.GettingToKnow.Structures 7 | import FPLean.GettingToKnow.DatatypesPatterns 8 | import FPLean.GettingToKnow.Polymorphism 9 | import FPLean.GettingToKnow.Conveniences 10 | import FPLean.GettingToKnow.Summary 11 | 12 | open Verso.Genre Manual 13 | open Verso Code External 14 | 15 | open FPLean 16 | 17 | set_option verso.exampleProject "../examples" 18 | set_option verso.exampleModule "Hello" 19 | 20 | 21 | #doc (Manual) "Getting to Know Lean" => 22 | %%% 23 | tag := "getting-to-know" 24 | %%% 25 | 26 | According to tradition, a programming language should be introduced by compiling and running a program that displays {moduleTerm}`"Hello, world!"` on the console. 27 | This simple program ensures that the language tooling is installed correctly and that the programmer is able to run the compiled code. 28 | 29 | Since the 1970s, however, programming has changed. 30 | Today, compilers are typically integrated into text editors, and the programming environment offers feedback as the program is written. 31 | Lean is no exception: it implements an extended version of the Language Server Protocol that allows it to communicate with a text editor and provide feedback as the user types. 32 | 33 | Languages as varied as Python, Haskell, and JavaScript offer a read-eval-print-loop (REPL), also known as an interactive toplevel or a browser console, in which expressions or statements can be entered. 34 | The language then computes and displays the result of the user's input. 35 | Lean, on the other hand, integrates these features into the interaction with the editor, providing commands that cause the text editor to display feedback integrated into the program text itself. 36 | This chapter provides a short introduction to interacting with Lean in an editor, while {ref "hello-world"}[Hello, World!] describes how to use Lean traditionally from the command line in batch mode. 37 | 38 | It is best if you read this book with Lean open in your editor, following along and typing in each example. Please play with the 39 | examples, and see what happens! 40 | 41 | {include 1 FPLean.GettingToKnow.Evaluating} 42 | 43 | {include 1 FPLean.GettingToKnow.Types} 44 | 45 | {include 1 FPLean.GettingToKnow.FunctionsDefinitions} 46 | 47 | {include 1 FPLean.GettingToKnow.Structures} 48 | 49 | {include 1 FPLean.GettingToKnow.DatatypesPatterns} 50 | 51 | {include 1 FPLean.GettingToKnow.Polymorphism} 52 | 53 | {include 1 FPLean.GettingToKnow.Conveniences} 54 | 55 | {include 1 FPLean.GettingToKnow.Summary} 56 | -------------------------------------------------------------------------------- /examples/Examples/ProgramsProofs/Fin.lean: -------------------------------------------------------------------------------- 1 | import ExampleSupport 2 | 3 | namespace FinDef 4 | 5 | -- ANCHOR: Fin 6 | structure Fin (n : Nat) where 7 | val : Nat 8 | isLt : LT.lt val n 9 | -- ANCHOR_END: Fin 10 | 11 | 12 | 13 | end FinDef 14 | 15 | --ANCHOR: sundries 16 | example := GetElem 17 | example := Array 18 | example := Nat 19 | example {n} := Fin n 20 | example : List (Fin 3) := [0, 1, 2] 21 | example := Fin 0 22 | example := @Subtype 23 | section 24 | variable {n k : Nat} 25 | #synth ToString (Fin n) 26 | #synth OfNat (Fin (n + 1)) k 27 | end 28 | --ANCHOR_END: sundries 29 | 30 | /-- info: 31 | 5 32 | -/ 33 | #check_msgs in 34 | -- ANCHOR: fiveFinEight 35 | #eval (5 : Fin 8) 36 | -- ANCHOR_END: fiveFinEight 37 | 38 | 39 | /-- info: 40 | 5 41 | -/ 42 | #check_msgs in 43 | -- ANCHOR: finOverflow 44 | #eval (45 : Fin 10) 45 | -- ANCHOR_END: finOverflow 46 | 47 | -- ANCHOR: exercise 48 | def Fin.next? (i : Fin n) : Option (Fin n) := 49 | if h : i.val + 1 < n then 50 | some ⟨i.val + 1, h⟩ 51 | else 52 | none 53 | 54 | section 55 | variable {n} 56 | #check (Fin.next? : Fin n → Option (Fin n)) 57 | end 58 | -- ANCHOR_END: exercise 59 | 60 | /-- info: 61 | some 4 62 | -/ 63 | #check_msgs in 64 | -- ANCHOR: nextThreeFin 65 | #eval (3 : Fin 8).next? 66 | -- ANCHOR_END: nextThreeFin 67 | 68 | 69 | /-- info: 70 | none 71 | -/ 72 | #check_msgs in 73 | -- ANCHOR: nextSevenFin 74 | #eval (7 : Fin 8).next? 75 | -- ANCHOR_END: nextSevenFin 76 | 77 | 78 | 79 | namespace Finny 80 | 81 | -- ANCHOR: ArrayFindHelper 82 | def findHelper (arr : Array α) (p : α → Bool) (i : Nat) : 83 | Option (Fin arr.size × α) := 84 | if h : i < arr.size then 85 | let x := arr[i] 86 | if p x then 87 | some (⟨i, h⟩, x) 88 | else findHelper arr p (i + 1) 89 | else none 90 | -- ANCHOR_END: ArrayFindHelper 91 | 92 | -- ANCHOR: ArrayFind 93 | def Array.find (arr : Array α) (p : α → Bool) : Option (Fin arr.size × α) := 94 | findHelper arr p 0 95 | -- ANCHOR_END: ArrayFind 96 | 97 | 98 | def arrayMapHelper (f : α → β) (arr : Array α) (soFar : Array β) (i : Fin arr.size) : Array β := 99 | let nextAccum := soFar.push (f arr[i]) 100 | if h : i.val + 1 < arr.size then 101 | have : Array.size arr - (i.val + 1) < Array.size arr - i.val := by 102 | apply Nat.sub_succ_lt_self 103 | exact i.isLt 104 | arrayMapHelper f arr nextAccum ⟨i + 1, h⟩ 105 | else 106 | nextAccum 107 | termination_by arr.size - i.val 108 | 109 | 110 | def Array.map (f : α → β) (arr : Array α) : Array β := 111 | if h : arr.size > 0 then 112 | arrayMapHelper f arr Array.empty ⟨0, h⟩ 113 | else 114 | Array.empty 115 | end Finny 116 | -------------------------------------------------------------------------------- /examples/Examples/ProgramsProofs/InstrumentedInsertionSort.lean: -------------------------------------------------------------------------------- 1 | -- ANCHOR: various 2 | example := IO.FS.Stream.getLine 3 | -- ANCHOR_END: various 4 | 5 | -- ANCHOR: InstrumentedInsertionSort 6 | def insertSorted [Ord α] (arr : Array α) (i : Fin arr.size) : Array α := 7 | match i with 8 | | ⟨0, _⟩ => arr 9 | | ⟨i' + 1, _⟩ => 10 | have : i' < arr.size := by 11 | omega 12 | match Ord.compare arr[i'] arr[i] with 13 | | .lt | .eq => arr 14 | | .gt => 15 | have : (dbgTraceIfShared "array to swap" arr).size = arr.size := by 16 | simp [dbgTraceIfShared] 17 | insertSorted 18 | ((dbgTraceIfShared "array to swap" arr).swap i' i) 19 | ⟨i', by simp [*]⟩ 20 | 21 | theorem insert_sorted_size_eq [Ord α] (len : Nat) (i : Nat) : 22 | (arr : Array α) → (isLt : i < arr.size) → (arr.size = len) → 23 | (insertSorted arr ⟨i, isLt⟩).size = len := by 24 | induction i with 25 | | zero => 26 | intro arr isLt hLen 27 | simp [insertSorted, *] 28 | | succ i' ih => 29 | intro arr isLt hLen 30 | simp [insertSorted, dbgTraceIfShared] 31 | split <;> simp [*] 32 | 33 | def insertionSortLoop [Ord α] (arr : Array α) (i : Nat) : Array α := 34 | if h : i < arr.size then 35 | have : (insertSorted arr ⟨i, h⟩).size - (i + 1) < arr.size - i := by 36 | rw [insert_sorted_size_eq arr.size i arr h rfl] 37 | omega 38 | insertionSortLoop (insertSorted arr ⟨i, h⟩) (i + 1) 39 | else 40 | arr 41 | termination_by arr.size - i 42 | 43 | def insertionSort [Ord α] (arr : Array α) : Array α := 44 | insertionSortLoop arr 0 45 | -- ANCHOR_END: InstrumentedInsertionSort 46 | 47 | -- ANCHOR: getLines 48 | def getLines : IO (Array String) := do 49 | let stdin ← IO.getStdin 50 | let mut lines : Array String := #[] 51 | let mut currLine ← stdin.getLine 52 | while !currLine.isEmpty do 53 | -- Drop trailing newline: 54 | lines := lines.push (currLine.dropRight 1) 55 | currLine ← stdin.getLine 56 | pure lines 57 | -- ANCHOR_END: getLines 58 | 59 | -- ANCHOR: mains 60 | def mainUnique : IO Unit := do 61 | let lines ← getLines 62 | for line in insertionSort lines do 63 | IO.println line 64 | 65 | def mainShared : IO Unit := do 66 | let lines ← getLines 67 | IO.println "--- Sorted lines: ---" 68 | for line in insertionSort lines do 69 | IO.println line 70 | 71 | IO.println "" 72 | IO.println "--- Original data: ---" 73 | for line in lines do 74 | IO.println line 75 | -- ANCHOR_END: mains 76 | 77 | -- ANCHOR: main 78 | def main (args : List String) : IO UInt32 := do 79 | match args with 80 | | ["--shared"] => mainShared; pure 0 81 | | ["--unique"] => mainUnique; pure 0 82 | | _ => 83 | IO.println "Expected single argument, either \"--shared\" or \"--unique\"" 84 | pure 1 85 | -- ANCHOR_END: main 86 | -------------------------------------------------------------------------------- /examples/Examples/MonadTransformers/Conveniences.lean: -------------------------------------------------------------------------------- 1 | import ExampleSupport 2 | 3 | #eval [3] |> List.reverse 4 | 5 | namespace PipelineEx 6 | 7 | variable (α : Type) 8 | variable (β : Type) 9 | variable (γ : Type) 10 | variable (δ : Type) 11 | 12 | variable (E₁ : α) 13 | variable (E₂ : α → β) 14 | variable (E₃ : β → γ) 15 | variable (E₄ : γ → δ) 16 | 17 | -- ANCHOR: pipelineShort 18 | example : ( 19 | E₁ |> E₂ 20 | ) = ( 21 | E₂ E₁ 22 | ) := rfl 23 | -- ANCHOR_END: pipelineShort 24 | 25 | 26 | -- ANCHOR: pipeline 27 | example : ( 28 | E₁ |> E₂ |> E₃ |> E₄ 29 | ) = ( 30 | E₄ (E₃ (E₂ E₁)) 31 | ) := rfl 32 | -- ANCHOR_END: pipeline 33 | 34 | 35 | /-- info: 36 | "(some 5)" 37 | -/ 38 | #check_msgs in 39 | -- ANCHOR: some5 40 | #eval some 5 |> toString 41 | -- ANCHOR_END: some5 42 | 43 | 44 | -- ANCHOR: times3 45 | def times3 (n : Nat) : Nat := n * 3 46 | -- ANCHOR_END: times3 47 | 48 | /-- info: 49 | "It is 15" 50 | -/ 51 | #check_msgs in 52 | -- ANCHOR: itIsFive 53 | #eval 5 |> times3 |> toString |> ("It is " ++ ·) 54 | -- ANCHOR_END: itIsFive 55 | 56 | 57 | /-- info: 58 | "It is 15" 59 | -/ 60 | #check_msgs in 61 | -- ANCHOR: itIsAlsoFive 62 | #eval ("It is " ++ ·) <| toString <| times3 <| 5 63 | -- ANCHOR_END: itIsAlsoFive 64 | 65 | /-- info: 66 | "It is 15" 67 | -/ 68 | #check_msgs in 69 | -- ANCHOR: itIsAlsoFiveParens 70 | #eval ("It is " ++ ·) (toString (times3 5)) 71 | -- ANCHOR_END: itIsAlsoFiveParens 72 | 73 | 74 | end PipelineEx 75 | 76 | -- ANCHOR: listReverse 77 | example : ( 78 | [1, 2, 3].reverse 79 | ) = ( 80 | List.reverse [1, 2, 3] 81 | ) := rfl 82 | -- ANCHOR_END: listReverse 83 | 84 | -- ANCHOR: listReverseDropReverse 85 | example : ( 86 | ([1, 2, 3].reverse.drop 1).reverse 87 | ) = ( 88 | [1, 2, 3] |> List.reverse |> List.drop 1 |> List.reverse 89 | ) := rfl 90 | -- ANCHOR_END: listReverseDropReverse 91 | 92 | -- ANCHOR: listReverseDropReversePipe 93 | example : ( 94 | [1, 2, 3] |> List.reverse |> List.drop 1 |> List.reverse 95 | ) = ( 96 | [1, 2, 3] |>.reverse |>.drop 1 |>.reverse 97 | ) := rfl 98 | -- ANCHOR_END: listReverseDropReversePipe 99 | 100 | 101 | -- ANCHOR: spam 102 | def spam : IO Unit := do 103 | repeat IO.println "Spam!" 104 | -- ANCHOR_END: spam 105 | 106 | 107 | def bufsize : USize := 20 * 1024 108 | 109 | 110 | -- ANCHOR: dump 111 | def dump (stream : IO.FS.Stream) : IO Unit := do 112 | let stdout ← IO.getStdout 113 | repeat do 114 | let buf ← stream.read bufsize 115 | if buf.isEmpty then break 116 | stdout.write buf 117 | -- ANCHOR_END: dump 118 | 119 | namespace More 120 | -- ANCHOR: dumpWhile 121 | def dump (stream : IO.FS.Stream) : IO Unit := do 122 | let stdout ← IO.getStdout 123 | let mut buf ← stream.read bufsize 124 | while not buf.isEmpty do 125 | stdout.write buf 126 | buf ← stream.read bufsize 127 | -- ANCHOR_END: dumpWhile 128 | end More 129 | 130 | -- ANCHOR: names 131 | example := ForM 132 | -- ANCHOR_END: names 133 | -------------------------------------------------------------------------------- /examples/Examples/Classes/Even.lean: -------------------------------------------------------------------------------- 1 | -- Example solution to the "even numbers" exercise, adapted from Chris Lovett's solution 2 | 3 | namespace Even 4 | inductive Even : Type where 5 | | zero : Even 6 | | plusTwo : Even → Even 7 | 8 | def Even.plus : Even → Even → Even 9 | | Even.zero, k => k 10 | | Even.plusTwo n, k => Even.plusTwo (n.plus k) 11 | 12 | instance : Add Even where 13 | add := Even.plus 14 | 15 | def eight : Even := 16 | Even.plusTwo (Even.plusTwo (Even.plusTwo (Even.plusTwo Even.zero))) 17 | 18 | def two : Even := 19 | Even.plusTwo Even.zero 20 | 21 | def Even.toNat : Even → Nat 22 | | Even.zero => 0 23 | | Even.plusTwo n => n.toNat + 2 24 | 25 | instance : ToString Even where 26 | toString x := toString (x.toNat) 27 | 28 | #eval eight + two -- 10 29 | 30 | #eval s!"There are {eight}" 31 | 32 | def Even.mul : Even → Even → Even 33 | | Even.zero, k => Even.zero 34 | | Even.plusTwo Even.zero, k => k + k 35 | | Even.plusTwo n, k => n.mul k + k + k 36 | 37 | instance : Mul Even where 38 | mul := Even.mul 39 | 40 | #eval eight * two -- 16 41 | 42 | instance : OfNat Even Nat.zero where 43 | ofNat := Even.zero 44 | 45 | instance [OfNat Even n] : OfNat Even (n + 2) where 46 | ofNat := Even.plusTwo (OfNat.ofNat n) 47 | 48 | #eval (2 : Even) 49 | 50 | #eval (8 : Even) * 2 -- 16 51 | end Even 52 | 53 | namespace Old 54 | 55 | inductive GEven : Nat → Type where 56 | | zero : (m : Nat) → GEven m 57 | | succ2 : {m : Nat} → GEven m → GEven m 58 | 59 | example : GEven 1 := .zero 1 60 | 61 | end Old 62 | 63 | namespace New 64 | 65 | inductive GEven (basis : Nat) : Nat → Type where 66 | | base : basis % 2 = 0 → GEven basis basis 67 | | plusTwo : GEven basis n → GEven basis (n + 2) 68 | 69 | 70 | 71 | theorem geven_is_even (n : Nat) (even : GEven basis n) : n % 2 = 0 := by 72 | induction even 73 | case base => simp [*] 74 | case plusTwo _ ih => 75 | have step (n : Nat) : (n + 2) % 2 = n % 2 := by 76 | have : (n + 2) % 2 = if 0 < 2 ∧ 2 ≤ n + 2 then (n + 2 - 2) % 2 else n + 2 := Nat.mod_eq (n + 2) 2 77 | have : 2 ≤ n + 2 := by simp 78 | simp [*, Nat.add_sub_self_right n 2] 79 | simp [*] 80 | 81 | theorem geven_is_ge (n : Nat) (even : GEven basis n) : n ≥ basis := by 82 | simp 83 | induction even 84 | case base => simp 85 | case plusTwo _ ih => 86 | constructor; constructor; assumption 87 | 88 | end New 89 | 90 | namespace Other 91 | 92 | inductive Even : Type where 93 | | times2 : Nat → Even 94 | deriving Repr 95 | 96 | def Even.add : Even → Even → Even 97 | | times2 a, times2 b => times2 (a + b) 98 | 99 | instance : Add Even where 100 | add := Even.add 101 | 102 | instance : OfNat Even .zero where 103 | ofNat := Even.times2 0 104 | 105 | instance [OfNat Even n] : OfNat Even (n + 2) where 106 | ofNat := OfNat.ofNat n + .times2 1 107 | 108 | #eval (0 : Even) 109 | 110 | #eval (22 : Even) 111 | 112 | end Other 113 | -------------------------------------------------------------------------------- /book/FPLean/ProgramsProofs.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | import FPLean.Examples 3 | 4 | import FPLean.ProgramsProofs.TailRecursion 5 | import FPLean.ProgramsProofs.TailRecursionProofs 6 | import FPLean.ProgramsProofs.ArraysTermination 7 | import FPLean.ProgramsProofs.Inequalities 8 | import FPLean.ProgramsProofs.Fin 9 | import FPLean.ProgramsProofs.InsertionSort 10 | import FPLean.ProgramsProofs.SpecialTypes 11 | import FPLean.ProgramsProofs.Summary 12 | 13 | 14 | open Verso.Genre Manual 15 | open Verso.Code.External 16 | 17 | open FPLean 18 | 19 | set_option verso.exampleProject "../examples" 20 | set_option verso.exampleModule "Examples.TODO" 21 | 22 | #doc (Manual) "Programming, Proving, and Performance" => 23 | 24 | This chapter is about programming. 25 | Programs need to compute the correct result, but they also need to do so efficiently. 26 | To write efficient functional programs, it's important to know both how to use data structures appropriately and how to think about the time and space needed to run a program. 27 | 28 | This chapter is also about proofs. 29 | One of the most important data structures for efficient programming in Lean is the array, but safe use of arrays requires proving that array indices are in bounds. 30 | Furthermore, most interesting algorithms on arrays do not follow the pattern of structural recursion—instead, they iterate over the array. 31 | While these algorithms terminate, Lean will not necessarily be able to automatically check this. 32 | Proofs can be used to demonstrate why a program terminates. 33 | 34 | Rewriting programs to make them faster often results in code that is more difficult to understand. 35 | Proofs can also show that two programs always compute the same answers, even if they do so with different algorithms or implementation techniques. 36 | In this way, the slow, straightforward program can serve as a specification for the fast, complicated version. 37 | 38 | Combining proofs and programming allows programs to be both safe and efficient. 39 | Proofs allow elision of run-time bounds checks, they render many tests unnecessary, and they provide an extremely high level of confidence in a program without introducing any runtime performance overhead. 40 | However, proving theorems about programs can be time consuming and expensive, so other tools are often more economical. 41 | 42 | Interactive theorem proving is a deep topic. 43 | This chapter provides only a taste, oriented towards the proofs that come up in practice while programming in Lean. 44 | Most interesting theorems are not closely related to programming. 45 | Please refer to {ref "next-steps"}[Next Steps] for a list of resources for learning more. 46 | Just as when learning programming, however, there's no substitute for hands-on experience when learning to write proofs—it's time to get started! 47 | 48 | {include 1 FPLean.ProgramsProofs.TailRecursion} 49 | 50 | {include 1 FPLean.ProgramsProofs.TailRecursionProofs} 51 | 52 | {include 1 FPLean.ProgramsProofs.ArraysTermination} 53 | 54 | {include 1 FPLean.ProgramsProofs.Inequalities} 55 | 56 | {include 1 FPLean.ProgramsProofs.Fin} 57 | 58 | {include 1 FPLean.ProgramsProofs.InsertionSort} 59 | 60 | {include 1 FPLean.ProgramsProofs.SpecialTypes} 61 | 62 | {include 1 FPLean.ProgramsProofs.Summary} 63 | -------------------------------------------------------------------------------- /book/FPLean/FunctorApplicativeMonad.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | import FPLean.Examples 3 | import FPLean.FunctorApplicativeMonad.Inheritance 4 | import FPLean.FunctorApplicativeMonad.Applicative 5 | import FPLean.FunctorApplicativeMonad.ApplicativeContract 6 | import FPLean.FunctorApplicativeMonad.Alternative 7 | import FPLean.FunctorApplicativeMonad.Universes 8 | import FPLean.FunctorApplicativeMonad.Complete 9 | import FPLean.FunctorApplicativeMonad.Summary 10 | 11 | 12 | open Verso.Genre Manual 13 | open Verso Code External 14 | 15 | open FPLean 16 | 17 | set_option verso.exampleProject "../examples" 18 | set_option verso.exampleModule "Examples.FunctorApplicativeMonad" 19 | 20 | #doc (Manual) "Functors, Applicative Functors, and Monads" => 21 | 22 | {anchorTerm FunctorPair}`Functor` and {moduleName}`Monad` both describe operations for types that are still waiting for a type argument. 23 | One way to understand them is that {anchorTerm FunctorPair}`Functor` describes containers in which the contained data can be transformed, and {moduleName}`Monad` describes an encoding of programs with side effects. 24 | This understanding is incomplete, however. 25 | After all, {moduleName}`Option` has instances for both {moduleName}`Functor` and {moduleName}`Monad`, and simultaneously represents an optional value _and_ a computation that might fail to return a value. 26 | 27 | From the perspective of data structures, {anchorName AlternativeOption}`Option` is a bit like a nullable type or like a list that can contain at most one entry. 28 | From the perspective of control structures, {anchorName AlternativeOption}`Option` represents a computation that might terminate early without a result. 29 | Typically, programs that use the {anchorName FunctorValidate}`Functor` instance are easiest to think of as using {anchorName AlternativeOption}`Option` as a data structure, while programs that use the {anchorName MonadExtends}`Monad` instance are easiest to think of as using {anchorName AlternativeOption}`Option` to allow early failure, but learning to use both of these perspectives fluently is an important part of becoming proficient at functional programming. 30 | 31 | There is a deeper relationship between functors and monads. 32 | It turns out that _every monad is a functor_. 33 | Another way to say this is that the monad abstraction is more powerful than the functor abstraction, because not every functor is a monad. 34 | Furthermore, there is an additional intermediate abstraction, called _applicative functors_, that has enough power to write many interesting programs and yet permits libraries that cannot use the {anchorName MonadExtends}`Monad` interface. 35 | The type class {anchorName ApplicativeValidate}`Applicative` provides the overloadable operations of applicative functors. 36 | Every monad is an applicative functor, and every applicative functor is a functor, but the converses do not hold. 37 | 38 | {include 1 FPLean.FunctorApplicativeMonad.Inheritance} 39 | 40 | {include 1 FPLean.FunctorApplicativeMonad.Applicative} 41 | 42 | {include 1 FPLean.FunctorApplicativeMonad.ApplicativeContract} 43 | 44 | {include 1 FPLean.FunctorApplicativeMonad.Alternative} 45 | 46 | {include 1 FPLean.FunctorApplicativeMonad.Universes} 47 | 48 | {include 1 FPLean.FunctorApplicativeMonad.Complete} 49 | 50 | {include 1 FPLean.FunctorApplicativeMonad.Summary} 51 | -------------------------------------------------------------------------------- /book/FPLean/ProgramsProofs/Fin.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | import FPLean.Examples 3 | 4 | open Verso.Genre Manual 5 | open Verso.Code.External 6 | 7 | open FPLean 8 | 9 | set_option verso.exampleProject "../examples" 10 | set_option verso.exampleModule "Examples.ProgramsProofs.Fin" 11 | 12 | #doc (Manual) "Bounded Numbers" => 13 | %%% 14 | tag := "Fin" 15 | %%% 16 | 17 | The {anchorTerm sundries}`GetElem` instance for {anchorName sundries}`Array` and {anchorName sundries}`Nat` requires a proof that the provided {anchorName sundries}`Nat` is smaller than the array. 18 | In practice, these proofs often end up being passed to functions along with the indices. 19 | Rather than passing an index and a proof separately, a type called {anchorName Fin}`Fin` can be used to bundle up the index and the proof into a single value. 20 | This can make code easier to read. 21 | 22 | The type {anchorTerm sundries}`Fin n` represents numbers that are strictly less than {anchorName sundries}`n`. 23 | In other words, {anchorTerm sundries}`Fin 3` describes {anchorTerm sundries}`0`, {anchorTerm sundries}`1`, and {anchorTerm sundries}`2`, while {anchorTerm sundries}`Fin 0` has no values at all. 24 | The definition of {anchorName Fin}`Fin` resembles {anchorName sundries}`Subtype`, as a {anchorTerm sundries}`Fin n` is a structure that contains a {anchorName Fin}`Nat` and a proof that it is less than {anchorName sundries}`n`: 25 | 26 | ```anchor Fin 27 | structure Fin (n : Nat) where 28 | val : Nat 29 | isLt : LT.lt val n 30 | ``` 31 | 32 | Lean includes instances of {anchorName sundries}`ToString` and {anchorName sundries}`OfNat` that allow {anchorName Fin}`Fin` values to be conveniently used as numbers. 33 | In other words, the output of {anchorTerm fiveFinEight}`#eval (5 : Fin 8)` is {anchorInfo fiveFinEight}`5`, rather than something like {lit}`{val := 5, isLt := _}`. 34 | 35 | Instead of failing when the provided number is larger than the bound, the {anchorName sundries}`OfNat` instance for {anchorName Fin}`Fin` returns a value modulo the bound. 36 | This means that {anchorTerm finOverflow}`#eval (45 : Fin 10)` results in {anchorInfo finOverflow}`5` rather than a compile-time error. 37 | 38 | In a return type, a {anchorName Fin}`Fin` returned as a found index makes its connection to the data structure in which it was found more clear. 39 | The {anchorName ArrayFind}`Array.find` in the {ref "proving-termination"}[previous section] returns an index that the caller cannot immediately use to perform lookups into the array, because the information about its validity has been lost. 40 | A more specific type results in a value that can be used without making the program significantly more complicated: 41 | 42 | ```anchor ArrayFindHelper 43 | def findHelper (arr : Array α) (p : α → Bool) (i : Nat) : 44 | Option (Fin arr.size × α) := 45 | if h : i < arr.size then 46 | let x := arr[i] 47 | if p x then 48 | some (⟨i, h⟩, x) 49 | else findHelper arr p (i + 1) 50 | else none 51 | ``` 52 | 53 | ```anchor ArrayFind 54 | def Array.find (arr : Array α) (p : α → Bool) : Option (Fin arr.size × α) := 55 | findHelper arr p 0 56 | ``` 57 | 58 | # Exercise 59 | %%% 60 | tag := "Fin-exercises" 61 | %%% 62 | 63 | Write a function {anchorTerm exercise}`Fin.next? : Fin n → Option (Fin n)` that returns the next largest {anchorName nextThreeFin}`Fin` when it would be in bounds, or {anchorName ArrayFindHelper}`none` if not. 64 | Check that 65 | ```anchor nextThreeFin 66 | #eval (3 : Fin 8).next? 67 | ``` 68 | outputs 69 | ```anchorInfo nextThreeFin 70 | some 4 71 | ``` 72 | and that 73 | ```anchor nextSevenFin 74 | #eval (7 : Fin 8).next? 75 | ``` 76 | outputs 77 | ```anchorInfo nextSevenFin 78 | none 79 | ``` 80 | -------------------------------------------------------------------------------- /book/static/fonts/source-sans/source-sans-3.css: -------------------------------------------------------------------------------- 1 | @font-face{ 2 | font-family: 'Source Sans 3'; 3 | font-weight: 200; 4 | font-style: normal; 5 | font-stretch: normal; 6 | src: url('WOFF2/TTF/SourceSans3-ExtraLight.ttf.woff2') format('woff2'), 7 | url('WOFF/OTF/SourceSans3-ExtraLight.otf.woff') format('woff'); 8 | } 9 | 10 | @font-face{ 11 | font-family: 'Source Sans 3'; 12 | font-weight: 200; 13 | font-style: italic; 14 | font-stretch: normal; 15 | src: url('WOFF2/TTF/SourceSans3-ExtraLightIt.ttf.woff2') format('woff2'), 16 | url('WOFF/OTF/SourceSans3-ExtraLightIt.otf.woff') format('woff'); 17 | } 18 | 19 | @font-face{ 20 | font-family: 'Source Sans 3'; 21 | font-weight: 300; 22 | font-style: normal; 23 | font-stretch: normal; 24 | src: url('WOFF2/TTF/SourceSans3-Light.ttf.woff2') format('woff2'), 25 | url('WOFF/OTF/SourceSans3-Light.otf.woff') format('woff'); 26 | } 27 | 28 | @font-face{ 29 | font-family: 'Source Sans 3'; 30 | font-weight: 300; 31 | font-style: italic; 32 | font-stretch: normal; 33 | src: url('WOFF2/TTF/SourceSans3-LightIt.ttf.woff2') format('woff2'), 34 | url('WOFF/OTF/SourceSans3-LightIt.otf.woff') format('woff'); 35 | } 36 | 37 | @font-face{ 38 | font-family: 'Source Sans 3'; 39 | font-weight: 400; 40 | font-style: normal; 41 | font-stretch: normal; 42 | src: url('WOFF2/TTF/SourceSans3-Regular.ttf.woff2') format('woff2'), 43 | url('WOFF/OTF/SourceSans3-Regular.otf.woff') format('woff'); 44 | } 45 | 46 | @font-face{ 47 | font-family: 'Source Sans 3'; 48 | font-weight: 400; 49 | font-style: italic; 50 | font-stretch: normal; 51 | src: url('WOFF2/TTF/SourceSans3-It.ttf.woff2') format('woff2'), 52 | url('WOFF/OTF/SourceSans3-It.otf.woff') format('woff'); 53 | } 54 | 55 | @font-face{ 56 | font-family: 'Source Sans 3'; 57 | font-weight: 600; 58 | font-style: normal; 59 | font-stretch: normal; 60 | src: url('WOFF2/TTF/SourceSans3-Semibold.ttf.woff2') format('woff2'), 61 | url('WOFF/OTF/SourceSans3-Semibold.otf.woff') format('woff'); 62 | } 63 | 64 | @font-face{ 65 | font-family: 'Source Sans 3'; 66 | font-weight: 600; 67 | font-style: italic; 68 | font-stretch: normal; 69 | src: url('WOFF2/TTF/SourceSans3-SemiboldIt.ttf.woff2') format('woff2'), 70 | url('WOFF/OTF/SourceSans3-SemiboldIt.otf.woff') format('woff'); 71 | } 72 | 73 | @font-face{ 74 | font-family: 'Source Sans 3'; 75 | font-weight: 700; 76 | font-style: normal; 77 | font-stretch: normal; 78 | src: url('WOFF2/TTF/SourceSans3-Bold.ttf.woff2') format('woff2'), 79 | url('WOFF/OTF/SourceSans3-Bold.otf.woff') format('woff'); 80 | } 81 | 82 | @font-face{ 83 | font-family: 'Source Sans 3'; 84 | font-weight: 700; 85 | font-style: italic; 86 | font-stretch: normal; 87 | src: url('WOFF2/TTF/SourceSans3-BoldIt.ttf.woff2') format('woff2'), 88 | url('WOFF/OTF/SourceSans3-BoldIt.otf.woff') format('woff'); 89 | } 90 | 91 | @font-face{ 92 | font-family: 'Source Sans 3'; 93 | font-weight: 900; 94 | font-style: normal; 95 | font-stretch: normal; 96 | src: url('WOFF2/TTF/SourceSans3-Black.ttf.woff2') format('woff2'), 97 | url('WOFF/OTF/SourceSans3-Black.otf.woff') format('woff'); 98 | } 99 | 100 | @font-face{ 101 | font-family: 'Source Sans 3'; 102 | font-weight: 900; 103 | font-style: italic; 104 | font-stretch: normal; 105 | src: url('WOFF2/TTF/SourceSans3-BlackIt.ttf.woff2') format('woff2'), 106 | url('WOFF/OTF/SourceSans3-BlackIt.otf.woff') format('woff'); 107 | } 108 | -------------------------------------------------------------------------------- /book/FPLean/NextSteps.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | import FPLean.Examples 3 | 4 | open Verso.Genre Manual 5 | open Verso.Code.External 6 | 7 | open FPLean 8 | 9 | #doc (Manual) "Next Steps" => 10 | %%% 11 | tag := "next-steps" 12 | htmlSplit := .never 13 | %%% 14 | 15 | This book introduces the very basics of functional programming in Lean, including a tiny amount of interactive theorem proving. 16 | Using dependently-typed functional languages like Lean is a deep topic, and much can be said. 17 | Depending on your interests, the following resources might be useful for learning Lean 4. 18 | 19 | # Learning Lean 20 | %%% 21 | tag := "learning-lean" 22 | %%% 23 | 24 | Lean 4 itself is described in the following resources: 25 | 26 | * [Theorem Proving in Lean 4](https://lean-lang.org/theorem_proving_in_lean4/) is a tutorial on writing proofs using Lean. 27 | * [The Lean 4 Manual](https://lean-lang.org/doc/reference/latest/) provides a detailed description of the language and its features. 28 | * [How To Prove It With Lean](https://djvelleman.github.io/HTPIwL/) is a Lean-based accompaniment to the well-regarded textbook [_How To Prove It_](https://www.cambridge.org/highereducation/books/how-to-prove-it/6D2965D625C6836CD4A785A2C843B3DA) that provides an introduction to writing paper-and-pencil mathematical proofs. 29 | * [Metaprogramming in Lean 4](https://github.com/arthurpaulino/lean4-metaprogramming-book) provides an overview of Lean's extension mechanisms, from infix operators and notations to macros, custom tactics, and full-on custom embedded languages. 30 | * [Functional Programming in Lean](https://lean-lang.org/functional_programming_in_lean/) may be interesting to readers who enjoy jokes about recursion. 31 | 32 | However, the best way to continue learning Lean is to start reading and writing code, consulting the documentation when you get stuck. 33 | Additionally, the [Lean Zulip](https://leanprover.zulipchat.com/) is an excellent place to meet other Lean users, ask for help, and help others. 34 | 35 | # Mathematics in Lean 36 | %%% 37 | tag := none 38 | %%% 39 | 40 | A wide selection of learning resources for mathematicians are available at [the community site](https://leanprover-community.github.io/learn.html). 41 | 42 | # Using Dependent Types in Computer Science 43 | %%% 44 | tag := none 45 | %%% 46 | 47 | Rocq is a language that has a lot in common with Lean. 48 | For computer scientists, the [Software Foundations](https://softwarefoundations.cis.upenn.edu/) series of interactive textbooks provides an excellent introduction to applications of Rocq in computer science. 49 | The fundamental ideas of Lean and Rocq are very similar, and skills are readily transferable between the systems. 50 | 51 | # Programming with Dependent Types 52 | %%% 53 | tag := none 54 | %%% 55 | 56 | For programmers who are interested in learning to use indexed families and dependent types to structure programs, Edwin Brady's [_Type Driven Development with Idris_](https://www.manning.com/books/type-driven-development-with-idris) provides an excellent introduction. 57 | Like Rocq, Idris is a close cousin of Lean, though it lacks tactics. 58 | 59 | # Understanding Dependent Types 60 | %%% 61 | tag := none 62 | %%% 63 | 64 | [_The Little Typer_](https://thelittletyper.com/) is a book for programmers who haven't formally studied logic or the theory of programming languages, but who want to build an understanding of the core ideas of dependent type theory. 65 | While all of the above resources aim to be as practical as possible, _The Little Typer_ presents an approach to dependent type theory where the very basics are built up from scratch, using only concepts from programming. 66 | Disclaimer: the author of _Functional Programming in Lean_ is also an author of _The Little Typer_. 67 | -------------------------------------------------------------------------------- /examples/Examples/HelloWorld.lean: -------------------------------------------------------------------------------- 1 | import ExampleSupport 2 | open SubVerso.Examples 3 | 4 | -- ANCHOR: MainTypes 5 | discarding 6 | def main : IO Unit := pure () 7 | stop discarding 8 | discarding 9 | def main : IO UInt32 := pure 0 10 | stop discarding 11 | discarding 12 | def main : List String → IO UInt32 := fun _ => pure 0 13 | stop discarding 14 | 15 | -- ANCHOR_END: MainTypes 16 | 17 | /-- info: 18 | "Hello" 19 | -/ 20 | #check_msgs in 21 | -- ANCHOR: dropBang 22 | #eval "Hello!!!".dropRightWhile (· == '!') 23 | -- ANCHOR_END: dropBang 24 | 25 | /-- info: 26 | "Hello" 27 | -/ 28 | #check_msgs in 29 | -- ANCHOR: dropNonLetter 30 | #eval "Hello... ".dropRightWhile (fun c => not (c.isAlphanum)) 31 | -- ANCHOR_END: dropNonLetter 32 | 33 | 34 | 35 | -- ANCHOR: twice 36 | def twice (action : IO Unit) : IO Unit := do 37 | action 38 | action 39 | -- ANCHOR_END: twice 40 | 41 | %show_name twice as twice.name 42 | 43 | /-- 44 | info: shy 45 | shy 46 | -/ 47 | #check_msgs in 48 | -- ANCHOR: twiceShy 49 | #eval twice (IO.println "shy") 50 | -- ANCHOR_END: twiceShy 51 | 52 | example := Nat.zero 53 | example := Nat.succ 54 | example := "Hello, David!" 55 | example := "David" 56 | example {α : Type} := IO α 57 | 58 | -- ANCHOR: nTimes 59 | def nTimes (action : IO Unit) : Nat → IO Unit 60 | | 0 => pure () 61 | | n + 1 => do 62 | action 63 | nTimes action n 64 | -- ANCHOR_END: nTimes 65 | 66 | -- ANCHOR: nTimes3 67 | #eval nTimes (IO.println "Hello") 3 68 | -- ANCHOR_END: nTimes3 69 | 70 | example : α → List α → List α := List.cons 71 | 72 | -- ANCHOR: countdown 73 | def countdown : Nat → List (IO Unit) 74 | | 0 => [IO.println "Blast off!"] 75 | | n + 1 => IO.println s!"{n + 1}" :: countdown n 76 | -- ANCHOR_END: countdown 77 | 78 | 79 | -- ANCHOR: from5 80 | def from5 : List (IO Unit) := countdown 5 81 | -- ANCHOR_END: from5 82 | 83 | 84 | /-- info: 85 | 6 86 | -/ 87 | #check_msgs in 88 | -- ANCHOR: from5length 89 | #eval from5.length 90 | -- ANCHOR_END: from5length 91 | -- ANCHOR: runActions 92 | def runActions : List (IO Unit) → IO Unit 93 | | [] => pure () 94 | | act :: actions => do 95 | act 96 | runActions actions 97 | -- ANCHOR_END: runActions 98 | 99 | 100 | -- ANCHOR: main 101 | def main : IO Unit := runActions from5 102 | -- ANCHOR_END: main 103 | 104 | /-- 105 | info: 5 106 | 4 107 | 3 108 | 2 109 | 1 110 | Blast off! 111 | -/ 112 | #check_msgs in 113 | -- ANCHOR: countdownFromFive 114 | #eval main 115 | -- ANCHOR_END: countdownFromFive 116 | 117 | evaluation steps : IO Unit {{{ evalMain }}} 118 | -- ANCHOR: evalMain 119 | main 120 | ===> 121 | runActions from5 122 | ===> 123 | runActions (countdown 5) 124 | ===> 125 | runActions 126 | [IO.println "5", 127 | IO.println "4", 128 | IO.println "3", 129 | IO.println "2", 130 | IO.println "1", 131 | IO.println "Blast off!"] 132 | ===> 133 | do IO.println "5" 134 | IO.println "4" 135 | IO.println "3" 136 | IO.println "2" 137 | IO.println "1" 138 | IO.println "Blast off!" 139 | pure () 140 | -- ANCHOR_END: evalMain 141 | end evaluation steps 142 | 143 | /-- info: 144 | 3 145 | 2 146 | 1 147 | Blast off! 148 | -/ 149 | #check_msgs in 150 | -- ANCHOR: evalDoesIO 151 | #eval runActions (countdown 3) 152 | -- ANCHOR_END: evalDoesIO 153 | 154 | -- Verify claim in book made about guillemets. The following should work: 155 | def «def» := 5 156 | 157 | namespace Exercises 158 | --ANCHOR: ExMain 159 | def main : IO Unit := do 160 | let englishGreeting := IO.println "Hello!" 161 | IO.println "Bonjour!" 162 | englishGreeting 163 | --ANCHOR_END: ExMain 164 | 165 | -- Part of a solution 166 | /-- info: 167 | Bonjour! 168 | Hello! 169 | 170 | -/ 171 | #check_msgs in 172 | -- ANCHOR: unused 173 | #eval main 174 | -- ANCHOR_END: unused 175 | end Exercises 176 | -------------------------------------------------------------------------------- /book/FPLean/Monads/Summary.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | import FPLean.Examples 3 | 4 | open Verso.Genre Manual 5 | open Verso Code External 6 | 7 | open FPLean 8 | 9 | set_option verso.exampleProject "../examples" 10 | set_option verso.exampleModule "Examples.Monads.Class" 11 | 12 | #doc (Manual) "Summary" => 13 | %%% 14 | tag := "monads-summary" 15 | %%% 16 | 17 | # Encoding Side Effects 18 | %%% 19 | tag := none 20 | %%% 21 | 22 | Lean is a pure functional language. 23 | This means that it does not include side effects such as mutable variables, logging, or exceptions. 24 | However, most side effects can be _encoded_ using a combination of functions and inductive types or structures. 25 | For example, mutable state can be encoded as a function from an initial state to a pair of a final state and a result, and exceptions can be encoded as an inductive type with constructors for successful termination and errors. 26 | 27 | Each set of encoded effects is a type. 28 | As a result, if a program uses these encoded effects, then this is apparent in its type. 29 | Functional programming does not mean that programs can't use effects, it simply requires that they be _honest_ about which effects they use. 30 | A Lean type signature describes not only the types of arguments that a function expects and the type of result that it returns, but also which effects it may use. 31 | 32 | # The Monad Type Class 33 | %%% 34 | tag := none 35 | %%% 36 | 37 | It's possible to write purely functional programs in languages that allow effects anywhere. 38 | For example, {python}`2 + 3` is a valid Python program that has no effects at all. 39 | Similarly, combining programs that have effects requires a way to state the order in which the effects must occur. 40 | It matters whether an exception is thrown before or after modifying a variable, after all. 41 | 42 | The type class {anchorName FakeMonad}`Monad` captures these two important properties. 43 | It has two methods: {anchorName FakeMonad}`pure` represents programs that have no effects, and {anchorName FakeMonad}`bind` sequences effectful programs. 44 | The contract for {anchorName FakeMonad}`Monad` instances ensures that {anchorName FakeMonad}`bind` and {anchorName FakeMonad}`pure` actually capture pure computation and sequencing. 45 | 46 | # {kw}`do`-Notation for Monads 47 | %%% 48 | tag := none 49 | %%% 50 | 51 | Rather than being limited to {moduleName}`IO`, {kw}`do`-notation works for any monad. 52 | It allows programs that use monads to be written in a style that is reminiscent of statement-oriented languages, with statements sequenced after one another. 53 | Additionally, {kw}`do`-notation enables a number of additional convenient shorthands, such as nested actions. 54 | A program written with {kw}`do` is translated to applications of {lit}`>>=` behind the scenes. 55 | 56 | # Custom Monads 57 | %%% 58 | tag := none 59 | %%% 60 | 61 | Different languages provide different sets of side effects. 62 | While most languages feature mutable variables and file I/O, not all have features like exceptions. 63 | Other languages offer effects that are rare or unique, like Icon's search-based program execution, Scheme and Ruby's continuations, and Common Lisp's resumable exceptions. 64 | An advantage to encoding effects with monads is that programs are not limited to the set of effects that are provided by the language. 65 | Because Lean is designed to make programming with any monad convenient, programmers are free to choose exactly the set of side effects that make sense for any given application. 66 | 67 | # The {lit}`IO` Monad 68 | %%% 69 | tag := none 70 | %%% 71 | 72 | Programs that can affect the real world are written as {moduleName}`IO` actions in Lean. 73 | {moduleName}`IO` is one monad among many. 74 | The {moduleName}`IO` monad encodes state and exceptions, with the state being used to keep track of the state of the world and the exceptions modeling failure and recovery. 75 | -------------------------------------------------------------------------------- /examples/Examples/Monads/Do.lean: -------------------------------------------------------------------------------- 1 | import ExampleSupport 2 | import Examples.Monads 3 | import Examples.Monads.Class 4 | 5 | set_option linter.unusedVariables false 6 | 7 | -- ANCHOR: names 8 | example := @HAdd.hAdd 9 | example := IO 10 | example := Unit 11 | section 12 | open List 13 | example := @map 14 | end 15 | -- ANCHOR_END: names 16 | 17 | section 18 | variable {m : Type → Type} [Monad m] {E : m α} {E₁ : m β} {E₂ : m γ} 19 | variable {Es : m Unit} {Stmt Stmt₁ : m Unit} {Eₙ : m ζ} 20 | 21 | 22 | 23 | local syntax "…" : term 24 | macro_rules 25 | | `(…) => `(Es) 26 | 27 | example : 28 | ( 29 | -- ANCHOR: doSugar1a 30 | do E 31 | -- ANCHOR_END: doSugar1a 32 | ) 33 | = 34 | -- ANCHOR: doSugar1b 35 | E 36 | -- ANCHOR_END: doSugar1b 37 | := rfl 38 | 39 | 40 | 41 | example : 42 | ( 43 | -- ANCHOR: doSugar2a 44 | do let x ← E₁ 45 | Stmt 46 | … 47 | Eₙ 48 | -- ANCHOR_END: doSugar2a 49 | ) = 50 | ( 51 | -- ANCHOR: doSugar2b 52 | E₁ >>= fun x => 53 | do Stmt 54 | … 55 | Eₙ 56 | -- ANCHOR_END: doSugar2b 57 | ) 58 | := rfl 59 | 60 | 61 | 62 | 63 | 64 | example : 65 | ( 66 | -- ANCHOR: doSugar4a 67 | do let x := E₁ 68 | Stmt 69 | … 70 | Eₙ 71 | -- ANCHOR_END: doSugar4a 72 | ) = 73 | ( 74 | -- ANCHOR: doSugar4b 75 | let x := E₁ 76 | do Stmt 77 | … 78 | Eₙ 79 | -- ANCHOR_END: doSugar4b 80 | ) 81 | := rfl 82 | 83 | 84 | variable {E₁ : m Unit} 85 | 86 | example : 87 | ( 88 | -- ANCHOR: doSugar3a 89 | do E₁ 90 | Stmt 91 | … 92 | Eₙ 93 | -- ANCHOR_END: doSugar3a 94 | ) = 95 | ( 96 | -- ANCHOR: doSugar3b 97 | E₁ >>= fun () => 98 | do Stmt 99 | … 100 | Eₙ 101 | -- ANCHOR_END: doSugar3b 102 | ) 103 | := rfl 104 | 105 | end 106 | 107 | namespace WithDo 108 | variable {α β : Type} {m : Type → Type} 109 | -- ANCHOR: firstThirdFifthSeventhDo 110 | def firstThirdFifthSeventh [Monad m] (lookup : List α → Nat → m α) 111 | (xs : List α) : m (α × α × α × α) := do 112 | let first ← lookup xs 0 113 | let third ← lookup xs 2 114 | let fifth ← lookup xs 4 115 | let seventh ← lookup xs 6 116 | pure (first, third, fifth, seventh) 117 | -- ANCHOR_END: firstThirdFifthSeventhDo 118 | 119 | 120 | -- ANCHOR: mapM 121 | def mapM [Monad m] (f : α → m β) : List α → m (List β) 122 | | [] => pure [] 123 | | x :: xs => do 124 | let hd ← f x 125 | let tl ← mapM f xs 126 | pure (hd :: tl) 127 | -- ANCHOR_END: mapM 128 | end WithDo 129 | 130 | section 131 | variable {α β : Type} {m : Type → Type} 132 | -- ANCHOR: mapMNested 133 | def mapM [Monad m] (f : α → m β) : List α → m (List β) 134 | | [] => pure [] 135 | | x :: xs => do 136 | pure ((← f x) :: (← mapM f xs)) 137 | -- ANCHOR_END: mapMNested 138 | end 139 | 140 | namespace Numbering 141 | 142 | open Monads.State 143 | instance : Monad (State σ) where 144 | pure x := fun s => (s, x) 145 | bind first next := 146 | fun s => 147 | let (s', x) := first s 148 | next x s' 149 | 150 | -- ANCHOR: numberDo 151 | def number (t : BinTree α) : BinTree (Nat × α) := 152 | let rec helper : BinTree α → State Nat (BinTree (Nat × α)) 153 | | BinTree.leaf => pure BinTree.leaf 154 | | BinTree.branch left x right => do 155 | let numberedLeft ← helper left 156 | let n ← get 157 | set (n + 1) 158 | let numberedRight ← helper right 159 | ok (BinTree.branch numberedLeft (n, x) numberedRight) 160 | (helper t 0).snd 161 | -- ANCHOR_END: numberDo 162 | 163 | namespace Short 164 | 165 | 166 | -- ANCHOR: numberDoShort 167 | def increment : State Nat Nat := do 168 | let n ← get 169 | set (n + 1) 170 | pure n 171 | 172 | def number (t : BinTree α) : BinTree (Nat × α) := 173 | let rec helper : BinTree α → State Nat (BinTree (Nat × α)) 174 | | BinTree.leaf => pure BinTree.leaf 175 | | BinTree.branch left x right => do 176 | pure 177 | (BinTree.branch 178 | (← helper left) 179 | ((← increment), x) 180 | (← helper right)) 181 | (helper t 0).snd 182 | -- ANCHOR_END: numberDoShort 183 | end Short 184 | 185 | end Numbering 186 | -------------------------------------------------------------------------------- /book/FPLean/MonadTransformers/Summary.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | import FPLean.Examples 3 | 4 | open Verso.Genre Manual 5 | open Verso.Code.External 6 | 7 | open FPLean 8 | 9 | set_option verso.exampleProject "../examples" 10 | set_option verso.exampleModule "Examples.MonadTransformers" 11 | 12 | #doc (Manual) "Summary" => 13 | %%% 14 | tag := "monad-transformer-summary" 15 | %%% 16 | 17 | # Combining Monads 18 | %%% 19 | tag := none 20 | %%% 21 | 22 | When writing a monad from scratch, there are design patterns that tend to describe the ways that each effect is added to the monad. 23 | Reader effects are added by having the monad's type be a function from the reader's environment, state effects are added by including a function from the initial state to the value paired with the final state, failure or exceptions are added by including a sum type in the return type, and logging or other output is added by including a product type in the return type. 24 | Existing monads can be made part of the return type as well, allowing their effects to be included in the new monad. 25 | 26 | These design patterns are made into a library of reusable software components by defining _monad transformers_, which add an effect to some base monad. 27 | Monad transformers take the simpler monad types as arguments, returning the enhanced monad types. 28 | At a minimum, a monad transformer should provide the following instances: 29 | 1. A {anchorName Summary}`Monad` instance that assumes the inner type is already a monad 30 | 2. A {anchorName Summary}`MonadLift` instance to translate an action from the inner monad to the transformed monad 31 | 32 | Monad transformers may be implemented as polymorphic structures or inductive datatypes, but they are most often implemented as functions from the underlying monad type to the enhanced monad type. 33 | 34 | # Type Classes for Effects 35 | %%% 36 | tag := none 37 | %%% 38 | 39 | A common design pattern is to implement a particular effect by defining a monad that has the effect, a monad transformer that adds it to another monad, and a type class that provides a generic interface to the effect. 40 | This allows programs to be written that merely specify which effects they need, so the caller can provide any monad that has the right effects. 41 | 42 | Sometimes, auxiliary type information (e.g. the state's type in a monad that provides state, or the exception's type in a monad that provides exceptions) is an output parameter, and sometimes it is not. 43 | The output parameter is most useful for simple programs that use each kind of effect only once, but it risks having the type checker commit to a the wrong type too early when multiple instances of the same effect are used in a given program. 44 | Thus, both versions are typically provided, with the ordinary-parameter version of the type class having a name that ends in {lit}`-Of`. 45 | 46 | # Monad Transformers Don't Commute 47 | %%% 48 | tag := none 49 | %%% 50 | 51 | It is important to note that changing the order of transformers in a monad can change the meaning of programs that use the monad. 52 | For instance, re-ordering {anchorName Summary}`StateT` and {anchorTerm Summary}`ExceptT` can result either in programs that lose state modifications when exceptions are thrown or programs that keep changes. 53 | While most imperative languages provide only the latter, the increased flexibility provided by monad transformers demands thought and attention to choose the correct variety for the task at hand. 54 | 55 | # {kw}`do`-Notation for Monad Transformers 56 | %%% 57 | tag := none 58 | %%% 59 | 60 | Lean's {kw}`do`-blocks support early return, in which the block is terminated with some value, locally mutable variables, {kw}`for`-loops with {kw}`break` and {kw}`continue`, and single-branched {kw}`if`-statements. 61 | While this may seem to be introducing imperative features that would get in the way of using Lean to write proofs, it is in fact nothing more than a more convenient syntax for certain common uses of monad transformers. 62 | Behind the scenes, whatever monad the {kw}`do`-block is written in is transformed by appropriate uses of {anchorName Summary}`ExceptT` and {anchorName Summary}`StateT` to support these additional effects. 63 | -------------------------------------------------------------------------------- /examples/Examples/Monads/Conveniences.lean: -------------------------------------------------------------------------------- 1 | import ExampleSupport 2 | import Examples.Classes 3 | 4 | set_option linter.unusedVariables false 5 | 6 | -- ANCHOR: SumNames 7 | example := Sum 8 | example := @Sum.inl 9 | example := @Sum.inr 10 | section 11 | open Sum 12 | example := @inl 13 | example := @inr 14 | end 15 | -- ANCHOR_END: SumNames 16 | 17 | namespace Old 18 | variable {α : Type} 19 | -- ANCHOR: equalHuhOld 20 | def equal? [BEq α] (x : α) (y : α) : Option α := 21 | if x == y then 22 | some x 23 | else 24 | none 25 | -- ANCHOR_END: equalHuhOld 26 | end Old 27 | 28 | 29 | namespace New 30 | variable {α : Type} 31 | -- ANCHOR: equalHuhNew 32 | def equal? [BEq α] (x y : α) : Option α := 33 | if x == y then 34 | some x 35 | else 36 | none 37 | -- ANCHOR_END: equalHuhNew 38 | end New 39 | 40 | example [BEq α] : Old.equal? (α := α) = New.equal? := by rfl 41 | 42 | namespace Old 43 | 44 | -- ANCHOR: mirrorOld 45 | def BinTree.mirror : BinTree α → BinTree α 46 | | BinTree.leaf => BinTree.leaf 47 | | BinTree.branch l x r => BinTree.branch (mirror r) x (mirror l) 48 | -- ANCHOR_END: mirrorOld 49 | end Old 50 | 51 | 52 | -- ANCHOR: mirrorNew 53 | def BinTree.mirror : BinTree α → BinTree α 54 | | .leaf => .leaf 55 | | .branch l x r => .branch (mirror r) x (mirror l) 56 | -- ANCHOR_END: mirrorNew 57 | 58 | -- ANCHOR: BinTreeEmpty 59 | def BinTree.empty : BinTree α := .leaf 60 | -- ANCHOR_END: BinTreeEmpty 61 | 62 | /-- info: 63 | BinTree.empty : BinTree Nat 64 | -/ 65 | #check_msgs in 66 | -- ANCHOR: emptyDot 67 | #check (.empty : BinTree Nat) 68 | -- ANCHOR_END: emptyDot 69 | 70 | -- ANCHOR: Weekday 71 | inductive Weekday where 72 | | monday 73 | | tuesday 74 | | wednesday 75 | | thursday 76 | | friday 77 | | saturday 78 | | sunday 79 | deriving Repr 80 | -- ANCHOR_END: Weekday 81 | 82 | namespace A 83 | 84 | -- ANCHOR: isWeekendA 85 | def Weekday.isWeekend (day : Weekday) : Bool := 86 | match day with 87 | | Weekday.saturday => true 88 | | Weekday.sunday => true 89 | | _ => false 90 | -- ANCHOR_END: isWeekendA 91 | end A 92 | 93 | namespace B 94 | -- ANCHOR: isWeekendB 95 | def Weekday.isWeekend (day : Weekday) : Bool := 96 | match day with 97 | | .saturday => true 98 | | .sunday => true 99 | | _ => false 100 | -- ANCHOR_END: isWeekendB 101 | end B 102 | 103 | namespace C 104 | -- ANCHOR: isWeekendC 105 | def Weekday.isWeekend (day : Weekday) : Bool := 106 | match day with 107 | | .saturday | .sunday => true 108 | | _ => false 109 | -- ANCHOR_END: isWeekendC 110 | end C 111 | 112 | namespace D 113 | variable {α : Type} 114 | -- ANCHOR: isWeekendD 115 | def Weekday.isWeekend : Weekday → Bool 116 | | .saturday | .sunday => true 117 | | _ => false 118 | -- ANCHOR_END: isWeekendD 119 | end D 120 | 121 | variable {α : Type} 122 | 123 | -- ANCHOR: condense 124 | def condense : α ⊕ α → α 125 | | .inl x | .inr x => x 126 | -- ANCHOR_END: condense 127 | 128 | 129 | -- ANCHOR: stringy 130 | def stringy : Nat ⊕ Weekday → String 131 | | .inl x | .inr x => s!"It is {repr x}" 132 | -- ANCHOR_END: stringy 133 | 134 | #eval stringy (.inl 5) 135 | #eval stringy (.inr .monday) 136 | 137 | 138 | -- ANCHOR: getTheNat 139 | def getTheNat : (Nat × α) ⊕ (Nat × β) → Nat 140 | | .inl (n, x) | .inr (n, y) => n 141 | -- ANCHOR_END: getTheNat 142 | 143 | 144 | 145 | /-- error: Unknown identifier `x` -/ 146 | #check_msgs in 147 | -- ANCHOR: getTheAlpha 148 | def getTheAlpha : (Nat × α) ⊕ (Nat × α) → α 149 | | .inl (n, x) | .inr (n, y) => x 150 | -- ANCHOR_END: getTheAlpha 151 | 152 | -- ANCHOR: getTheString 153 | def str := "Some string" 154 | 155 | def getTheString : (Nat × String) ⊕ (Nat × β) → String 156 | | .inl (n, str) | .inr (n, y) => str 157 | -- ANCHOR_END: getTheString 158 | 159 | 160 | /-- info: 161 | "twenty" 162 | -/ 163 | #check_msgs in 164 | -- ANCHOR: getOne 165 | #eval getTheString (.inl (20, "twenty") : (Nat × String) ⊕ (Nat × String)) 166 | -- ANCHOR_END: getOne 167 | 168 | 169 | /-- info: 170 | "Some string" 171 | -/ 172 | #check_msgs in 173 | -- ANCHOR: getTwo 174 | #eval getTheString (.inr (20, "twenty")) 175 | -- ANCHOR_END: getTwo 176 | -------------------------------------------------------------------------------- /book/FPLean/GettingToKnow/Types.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | import FPLean.Examples 3 | 4 | open Verso.Genre Manual 5 | open Verso Code External 6 | 7 | open FPLean 8 | 9 | example_module Examples.Intro 10 | 11 | set_option verso.exampleProject "../examples" 12 | set_option verso.exampleModule "Examples.Intro" 13 | 14 | 15 | #doc (Manual) "Types" => 16 | %%% 17 | tag := "getting-to-know-types" 18 | %%% 19 | 20 | Types classify programs based on the values that they can 21 | compute. Types serve a number of roles in a program: 22 | 23 | 1. They allow the compiler to make decisions about the in-memory representation of a value. 24 | 25 | 2. They help programmers to communicate their intent to others, serving as a lightweight specification for the inputs and outputs of a function. 26 | The compiler ensures that the program adheres to this specification. 27 | 28 | 3. They prevent various potential mistakes, such as adding a number to a string, and thus reduce the number of tests that are necessary for a program. 29 | 30 | 4. They help the Lean compiler automate the production of auxiliary code that can save boilerplate. 31 | 32 | Lean's type system is unusually expressive. 33 | Types can encode strong specifications like “this sorting function returns a permutation of its input” and flexible specifications like “this function has different return types, depending on the value of its argument”. 34 | The type system can even be used as a full-blown logic for proving mathematical theorems. 35 | This cutting-edge expressive power doesn't make simpler types unnecessary, however, and understanding these simpler types is a prerequisite for using the more advanced features. 36 | 37 | :::paragraph 38 | Every program in Lean must have a type. In particular, every 39 | expression must have a type before it can be evaluated. In the 40 | examples so far, Lean has been able to discover a type on its own, but 41 | it is sometimes necessary to provide one. This is done using the colon 42 | operator inside parentheses: 43 | 44 | ```anchor onePlusTwoEval 45 | #eval (1 + 2 : Nat) 46 | ``` 47 | 48 | 49 | Here, {anchorName onePlusTwoEval}`Nat` is the type of _natural numbers_, which are arbitrary-precision unsigned integers. 50 | In Lean, {anchorName onePlusTwoEval}`Nat` is the default type for non-negative integer literals. 51 | This default type is not always the best choice. 52 | In C, unsigned integers underflow to the largest representable numbers when subtraction would otherwise yield a result less than zero. 53 | {anchorName onePlusTwoEval}`Nat`, however, can represent arbitrarily-large unsigned numbers, so there is no largest number to underflow to. 54 | Thus, subtraction on {anchorName onePlusTwoEval}`Nat` returns {anchorName Nat}`zero` when the answer would have otherwise been negative. 55 | For instance, 56 | 57 | ```anchor oneMinusTwoEval 58 | #eval (1 - 2 : Nat) 59 | ``` 60 | 61 | evaluates to {anchorInfo oneMinusTwoEval}`0` rather than {lit}`-1`. 62 | To use a type that can represent the negative integers, provide it directly: 63 | 64 | ```anchor oneMinusTwoIntEval 65 | #eval (1 - 2 : Int) 66 | ``` 67 | 68 | With this type, the result is {anchorInfo oneMinusTwoIntEval}`-1`, as expected. 69 | ::: 70 | 71 | :::paragraph 72 | To check the type of an expression without evaluating it, use {kw}`#check` instead of {kw}`#eval`. For instance: 73 | 74 | ```anchor oneMinusTwoIntType 75 | #check (1 - 2 : Int) 76 | ``` 77 | 78 | reports {anchorInfo oneMinusTwoIntType}`1 - 2 : Int` without actually performing the subtraction. 79 | ::: 80 | 81 | :::paragraph 82 | When a program can't be given a type, an error is returned from both {kw}`#check` and {kw}`#eval`. For instance: 83 | 84 | ```anchor stringAppendList 85 | #check String.append ["hello", " "] "world" 86 | ``` 87 | 88 | outputs 89 | 90 | ```anchorError stringAppendList 91 | Application type mismatch: The argument 92 | ["hello", " "] 93 | has type 94 | List String 95 | but is expected to have type 96 | String 97 | in the application 98 | String.append ["hello", " "] 99 | ``` 100 | 101 | because the first argument to {anchorName stringAppendList}`String.append` is expected to be a string, but a list of strings was provided instead. 102 | ::: 103 | -------------------------------------------------------------------------------- /examples/Examples/DependentTypes/IndicesParameters.lean: -------------------------------------------------------------------------------- 1 | import ExampleSupport 2 | import Examples.DependentTypes 3 | 4 | -- ANCHOR: WithParameter 5 | inductive WithParameter (α : Type u) : Type u where 6 | | test : α → WithParameter α 7 | -- ANCHOR_END: WithParameter 8 | 9 | 10 | -- ANCHOR: WithTwoParameters 11 | inductive WithTwoParameters (α : Type u) (β : Type v) : Type (max u v) where 12 | | test : α → β → WithTwoParameters α β 13 | -- ANCHOR_END: WithTwoParameters 14 | 15 | 16 | -- ANCHOR: WithParameterAfterColon 17 | inductive WithParameterAfterColon : Type u → Type u where 18 | | test : α → WithParameterAfterColon α 19 | -- ANCHOR_END: WithParameterAfterColon 20 | 21 | 22 | -- ANCHOR: WithParameterAfterColon2 23 | inductive WithParameterAfterColon2 : Type u → Type u where 24 | | test1 : α → WithParameterAfterColon2 α 25 | | test2 : WithParameterAfterColon2 α 26 | -- ANCHOR_END: WithParameterAfterColon2 27 | 28 | 29 | 30 | -- ANCHOR: WithParameterAfterColonDifferentNames 31 | inductive WithParameterAfterColonDifferentNames : Type u → Type u where 32 | | test1 : α → WithParameterAfterColonDifferentNames α 33 | | test2 : β → WithParameterAfterColonDifferentNames β 34 | -- ANCHOR_END: WithParameterAfterColonDifferentNames 35 | 36 | 37 | /-- 38 | error: Mismatched inductive type parameter in 39 | WithParameterBeforeColonDifferentNames β 40 | The provided argument 41 | β 42 | is not definitionally equal to the expected parameter 43 | α 44 | 45 | Note: The value of parameter `α` must be fixed throughout the inductive declaration. Consider making this parameter an index if it must vary. 46 | -/ 47 | #check_msgs in 48 | -- ANCHOR: WithParameterBeforeColonDifferentNames 49 | inductive WithParameterBeforeColonDifferentNames (α : Type u) : Type u where 50 | | test1 : α → WithParameterBeforeColonDifferentNames α 51 | | test2 : β → WithParameterBeforeColonDifferentNames β 52 | -- ANCHOR_END: WithParameterBeforeColonDifferentNames 53 | 54 | /-- 55 | error: Mismatched inductive type parameter in 56 | WithNamedIndex (α × α) 57 | The provided argument 58 | α × α 59 | is not definitionally equal to the expected parameter 60 | α 61 | 62 | Note: The value of parameter `α` must be fixed throughout the inductive declaration. Consider making this parameter an index if it must vary. 63 | -/ 64 | #check_msgs in 65 | -- ANCHOR: WithNamedIndex 66 | inductive WithNamedIndex (α : Type u) : Type (u + 1) where 67 | | test1 : WithNamedIndex α 68 | | test2 : WithNamedIndex α → WithNamedIndex α → WithNamedIndex (α × α) 69 | -- ANCHOR_END: WithNamedIndex 70 | 71 | 72 | -- ANCHOR: WithIndex 73 | inductive WithIndex : Type u → Type (u + 1) where 74 | | test1 : WithIndex α 75 | | test2 : WithIndex α → WithIndex α → WithIndex (α × α) 76 | -- ANCHOR_END: WithIndex 77 | 78 | /-- 79 | error: Invalid universe level in constructor `ParamAfterIndex.test1`: Parameter `γ` has type 80 | Type u 81 | at universe level 82 | u+2 83 | which is not less than or equal to the inductive type's resulting universe level 84 | u+1 85 | -/ 86 | #check_msgs in 87 | -- ANCHOR: ParamAfterIndex 88 | inductive ParamAfterIndex : Nat → Type u → Type u where 89 | | test1 : ParamAfterIndex 0 γ 90 | | test2 : ParamAfterIndex n γ → ParamAfterIndex k γ → ParamAfterIndex (n + k) γ 91 | -- ANCHOR_END: ParamAfterIndex 92 | 93 | 94 | /-- 95 | error: Mismatched inductive type parameter in 96 | NatParam 4 5 97 | The provided argument 98 | 4 99 | is not definitionally equal to the expected parameter 100 | n 101 | 102 | Note: The value of parameter `n` must be fixed throughout the inductive declaration. Consider making this parameter an index if it must vary. 103 | -/ 104 | #check_msgs in 105 | -- ANCHOR: NatParamFour 106 | inductive NatParam (n : Nat) : Nat → Type u where 107 | | five : NatParam 4 5 108 | -- ANCHOR_END: NatParamFour 109 | 110 | 111 | -- ANCHOR: NatParam 112 | inductive NatParam (n : Nat) : Nat → Type u where 113 | | five : NatParam n 5 114 | -- ANCHOR_END: NatParam 115 | 116 | 117 | /-- info: 118 | inductive Vect.{u} : Type u → Nat → Type u 119 | number of parameters: 1 120 | constructors: 121 | Vect.nil : {α : Type u} → Vect α 0 122 | Vect.cons : {α : Type u} → {n : Nat} → α → Vect α n → Vect α (n + 1) 123 | -/ 124 | #check_msgs in 125 | -- ANCHOR: printVect 126 | #print Vect 127 | -- ANCHOR_END: printVect 128 | -------------------------------------------------------------------------------- /book/FPLean/DependentTypes.lean: -------------------------------------------------------------------------------- 1 | import VersoManual 2 | import FPLean.Examples 3 | 4 | import FPLean.DependentTypes.IndexedFamilies 5 | import FPLean.DependentTypes.UniversePattern 6 | import FPLean.DependentTypes.TypedQueries 7 | import FPLean.DependentTypes.IndicesParametersUniverses 8 | import FPLean.DependentTypes.Pitfalls 9 | import FPLean.DependentTypes.Summary 10 | 11 | open Verso.Genre Manual 12 | open Verso.Code.External 13 | 14 | open FPLean 15 | 16 | set_option verso.exampleProject "../examples" 17 | set_option verso.exampleModule "Examples.DependentTypes" 18 | 19 | #doc (Manual) "Programming with Dependent Types" => 20 | 21 | In most statically-typed programming languages, there is a hermetic seal between the world of types and the world of programs. 22 | Types and programs have different grammars and they are used at different times. 23 | Types are typically used at compile time, to check that a program obeys certain invariants. 24 | Programs are used at run time, to actually perform computations. 25 | When the two interact, it is usually in the form of a type-case operator like an “instance-of” check or a casting operator that provides the type checker with information that was otherwise unavailable, to be verified at run time. 26 | In other words, the interaction consists of types being inserted into the world of programs, where they gain some limited run-time meaning. 27 | 28 | Lean does not impose this strict separation. 29 | In Lean, programs may compute types and types may contain programs. 30 | Placing programs in types allows their full computational power to be used at compile time, and the ability to return types from functions makes types into first-class participants in the programming process. 31 | 32 | _Dependent types_ are types that contain non-type expressions. 33 | A common source of dependent types is a named argument to a function. 34 | For example, the function {anchorName natOrStringThree}`natOrStringThree` returns either a natural number or a string, depending on which {anchorName natOrStringThree}`Bool` it is passed: 35 | 36 | ```anchor natOrStringThree 37 | def natOrStringThree (b : Bool) : if b then Nat else String := 38 | match b with 39 | | true => (3 : Nat) 40 | | false => "three" 41 | ``` 42 | 43 | Further examples of dependent types include: 44 | * {ref "polymorphism"}[The introductory section on polymorphism] contains {anchorName posOrNegThree (module:= Examples.Intro)}`posOrNegThree`, in which the function's return type depends on the value of the argument. 45 | * {ref "literal-numbers"}[The {anchorName OfNat (module := Examples.Classes)}`OfNat` type class] depends on the specific natural number literal being used. 46 | * {ref "validated-input"}[The {anchorName CheckedInput (module := Examples.FunctorApplicativeMonad)}`CheckedInput` structure] used in the example of validators depends on the year in which validation occurred. 47 | * {ref "subtypes"}[Subtypes] contain propositions that refer to particular values. 48 | * Essentially all interesting propositions, including those that determine the validity of {ref "props-proofs-indexing"}[array indexing notation], are types that contain values and are thus dependent types. 49 | 50 | Dependent types vastly increase the power of a type system. 51 | The flexibility of return types that branch on argument values enables programs to be written that cannot easily be given types in other type systems. 52 | At the same time, dependent types allow a type signature to restrict which values may be returned from a function, enabling strong invariants to be enforced at compile time. 53 | 54 | However, programming with dependent types can be quite complex, and it requires a whole set of skills above and beyond functional programming. 55 | Expressive specifications can be complicated to fulfill, and there is a real risk of tying oneself in knots and being unable to complete the program. 56 | On the other hand, this process can lead to new understanding, which can be expressed in a refined type that can be fulfilled. 57 | While this chapter scratches the surface of dependently typed programming, it is a deep topic that deserves an entire book of its own. 58 | 59 | {include 1 FPLean.DependentTypes.IndexedFamilies} 60 | 61 | {include 1 FPLean.DependentTypes.UniversePattern} 62 | 63 | {include 1 FPLean.DependentTypes.TypedQueries} 64 | 65 | {include 1 FPLean.DependentTypes.IndicesParametersUniverses} 66 | 67 | {include 1 FPLean.DependentTypes.Pitfalls} 68 | 69 | {include 1 FPLean.DependentTypes.Summary} 70 | -------------------------------------------------------------------------------- /examples/Examples/Monads/IO.lean: -------------------------------------------------------------------------------- 1 | import ExampleSupport 2 | 3 | -- ANCHOR: names 4 | example := IO 5 | section 6 | local instance : Monad IO where 7 | pure := pure 8 | bind := bind 9 | universe u 10 | example {ε} {α}:= EIO ε α 11 | -- ANCHOR: EStateMNames 12 | example {ε} {α} {σ} := EST ε σ α → EST.Out ε σ α 13 | -- ANCHOR_END: EStateMNames 14 | example := @EST.Out.ok 15 | example := @EST.Out.error 16 | example {α}:= BaseIO α 17 | example {ε} := Except ε 18 | example := Type u 19 | end 20 | -- ANCHOR_END: names 21 | 22 | /-- info: 23 | inductive Nat : Type 24 | number of parameters: 0 25 | constructors: 26 | Nat.zero : Nat 27 | Nat.succ : Nat → Nat 28 | -/ 29 | #check_msgs in 30 | -- ANCHOR: printNat 31 | #print Nat 32 | -- ANCHOR_END: printNat 33 | 34 | 35 | /-- info: 36 | def Char.isAlpha : Char → Bool := 37 | fun c => c.isUpper || c.isLower 38 | -/ 39 | #check_msgs in 40 | -- ANCHOR: printCharIsAlpha 41 | #print Char.isAlpha 42 | -- ANCHOR_END: printCharIsAlpha 43 | 44 | 45 | /-- info: 46 | def List.isEmpty.{u} : {α : Type u} → List α → Bool := 47 | fun {α} x => 48 | match x with 49 | | [] => true 50 | | head :: tail => false 51 | -/ 52 | #check_msgs in 53 | -- ANCHOR: printListIsEmpty 54 | #print List.isEmpty 55 | -- ANCHOR_END: printListIsEmpty 56 | 57 | 58 | 59 | /-- info: 60 | @[reducible] def IO : Type → Type := 61 | EIO IO.Error 62 | -/ 63 | #check_msgs in 64 | -- ANCHOR: printIO 65 | #print IO 66 | -- ANCHOR_END: printIO 67 | 68 | 69 | 70 | /-- info: 71 | inductive IO.Error : Type 72 | number of parameters: 0 73 | constructors: 74 | IO.Error.alreadyExists : Option String → UInt32 → String → IO.Error 75 | IO.Error.otherError : UInt32 → String → IO.Error 76 | IO.Error.resourceBusy : UInt32 → String → IO.Error 77 | IO.Error.resourceVanished : UInt32 → String → IO.Error 78 | IO.Error.unsupportedOperation : UInt32 → String → IO.Error 79 | IO.Error.hardwareFault : UInt32 → String → IO.Error 80 | IO.Error.unsatisfiedConstraints : UInt32 → String → IO.Error 81 | IO.Error.illegalOperation : UInt32 → String → IO.Error 82 | IO.Error.protocolError : UInt32 → String → IO.Error 83 | IO.Error.timeExpired : UInt32 → String → IO.Error 84 | IO.Error.interrupted : String → UInt32 → String → IO.Error 85 | IO.Error.noFileOrDirectory : String → UInt32 → String → IO.Error 86 | IO.Error.invalidArgument : Option String → UInt32 → String → IO.Error 87 | IO.Error.permissionDenied : Option String → UInt32 → String → IO.Error 88 | IO.Error.resourceExhausted : Option String → UInt32 → String → IO.Error 89 | IO.Error.inappropriateType : Option String → UInt32 → String → IO.Error 90 | IO.Error.noSuchThing : Option String → UInt32 → String → IO.Error 91 | IO.Error.unexpectedEof : IO.Error 92 | IO.Error.userError : String → IO.Error 93 | -/ 94 | #check_msgs in 95 | -- ANCHOR: printIOError 96 | #print IO.Error 97 | -- ANCHOR_END: printIOError 98 | 99 | 100 | /-- info: 101 | def EIO : Type → Type → Type := 102 | fun ε α => EST ε IO.RealWorld α 103 | -/ 104 | #check_msgs in 105 | -- ANCHOR: printEIO 106 | #print EIO 107 | -- ANCHOR_END: printEIO 108 | 109 | -- ANCHOR: VoidSigma 110 | example {σ} := Void σ 111 | -- ANCHOR_END: VoidSigma 112 | 113 | -- ANCHOR: RealWorld 114 | example := IO.RealWorld 115 | -- ANCHOR_END: RealWorld 116 | 117 | 118 | /-- info: 119 | def EST : Type → Type → Type → Type := 120 | fun ε σ α => Void σ → EST.Out ε σ α 121 | -/ 122 | #check_msgs in 123 | -- ANCHOR: printEStateM 124 | #print EST 125 | -- ANCHOR_END: printEStateM 126 | 127 | 128 | /-- info: 129 | inductive EST.Out : Type → Type → Type → Type 130 | number of parameters: 3 131 | constructors: 132 | EST.Out.ok : {ε σ α : Type} → α → Void σ → EST.Out ε σ α 133 | EST.Out.error : {ε σ α : Type} → ε → Void σ → EST.Out ε σ α 134 | -/ 135 | #check_msgs in 136 | -- ANCHOR: printEStateMResult 137 | #print EST.Out 138 | -- ANCHOR_END: printEStateMResult 139 | 140 | 141 | /-- info: 142 | protected def EST.pure : {α ε σ : Type} → α → EST ε σ α := 143 | fun {α ε σ} a s => EST.Out.ok a s 144 | -/ 145 | #check_msgs in 146 | -- ANCHOR: printEStateMpure 147 | #print EST.pure 148 | -- ANCHOR_END: printEStateMpure 149 | 150 | /-- info: 151 | protected def EST.bind : {ε σ α β : Type} → EST ε σ α → (α → EST ε σ β) → EST ε σ β := 152 | fun {ε σ α β} x f s => 153 | match x s with 154 | | EST.Out.ok a s => f a s 155 | | EST.Out.error e s => EST.Out.error e s 156 | -/ 157 | #check_msgs in 158 | -- ANCHOR: printEStateMbind 159 | #print EST.bind 160 | -- ANCHOR_END: printEStateMbind 161 | -------------------------------------------------------------------------------- /book/FPLean/Examples/Commands.lean: -------------------------------------------------------------------------------- 1 | import FPLean.Examples.Commands.Env 2 | import FPLean.Examples.Commands.ShLex 3 | import Lean.Elab 4 | import Verso.FS 5 | 6 | namespace FPLean.Commands 7 | open Lean 8 | 9 | variable {m : _} [Monad m] [MonadEnv m] [MonadLiftT IO m] [MonadLiftT BaseIO m] [MonadError m] 10 | 11 | def ensureContainer (container : Ident) : m Container := do 12 | let name := container.getId 13 | if let some c := (containersExt.getState (← getEnv)).find? name then return c 14 | let tmp ← IO.FS.createTempDir 15 | let c : Container := ⟨tmp, {}⟩ 16 | let projectRoot : System.FilePath := ".." 17 | let copyErrors : IO.Ref (Array String) ← IO.mkRef #[] 18 | Verso.FS.copyRecursively (fun s => copyErrors.modify (·.push s)) projectRoot tmp shouldCopy 19 | let errs ← (copyErrors.get : IO _) 20 | unless errs.isEmpty do 21 | throwErrorAt container "Errors copying project to container {name}: {indentD <| MessageData.joinSep (errs.toList.map toMessageData) Format.line}" 22 | modifyEnv (containersExt.modifyState · (·.insert name c)) 23 | return c 24 | where 25 | shouldCopy (path : System.FilePath) : IO Bool := do 26 | let some x := path.fileName 27 | | return true 28 | return !(x.startsWith ".") && !(x == "site-packages") && !(x == "_out") && !(x == "static") 29 | 30 | def requireContainer (container : Ident) : m Container := do 31 | let name := container.getId 32 | if let some c := (containersExt.getState (← getEnv)).find? name then return c 33 | else throwErrorAt container "Not found: '{name}'" 34 | 35 | private def localeVars : Array String := 36 | #["LANG", "LC_ALL"] 37 | 38 | private def lakeVars : Array String := 39 | #["ELAN_TOOLCHAIN", "LEAN_SYSROOT", "LEAN", "LAKE", "LAKE_HOME", "LEAN_PATH", "LAKE_CACHE_DIR", "LEAN_AR", "LEAN_CC", "DYLD_LIBRARY_PATH"] 40 | 41 | private def fixPath (path : String) := 42 | System.SearchPath.parse path 43 | |>.iter 44 | |>.map (·.toString) 45 | |>.filter (fun p => ((p.find? ".elan").isNone || (p.find? "toolchains").isNone)) 46 | |>.toList 47 | |> System.SearchPath.separator.toString.intercalate 48 | 49 | 50 | def command (container : Ident) (dir : System.FilePath) (command : StrLit) (viaShell := false) : m IO.Process.Output := do 51 | let c ← ensureContainer container 52 | unless dir.isRelative do 53 | throwError "Relative directory expected, got '{dir}'" 54 | let dir := c.workingDirectory / "examples" / dir 55 | IO.FS.createDirAll dir 56 | let (cmd, args) ← if viaShell then pure ("bash", #["-c", command.getString]) else cmdAndArgs 57 | let extraPath := (← IO.currentDir) / ".." / "examples" / ".lake" / "build" / "bin" |>.toString 58 | let extraPath := if extraPath.contains ' ' || extraPath.contains '"' || extraPath.contains '\'' then extraPath.quote else extraPath 59 | let path := (← IO.getEnv "PATH").map (System.SearchPath.separator.toString ++ ·) |>.getD "" 60 | let out ← IO.Process.output { 61 | cmd := cmd, 62 | args := args, 63 | cwd := dir, 64 | env := #[("PATH", some (extraPath ++ fixPath path))] ++ lakeVars.map (·, none) ++ localeVars.map (·, some "C.UTF-8") 65 | } 66 | if out.exitCode != 0 then 67 | let stdout := m!"Stdout: {indentD out.stdout}" 68 | let stderr := m!"Stderr: {indentD out.stderr}" 69 | throwErrorAt command "Non-zero exit code from '{command.getString}' ({out.exitCode}).\n{indentD stdout}\n{indentD stderr}" 70 | modifyEnv (containersExt.modifyState · (·.insert container.getId { c with outputs := c.outputs.insert command.getString.trimAscii.copy out.stdout })) 71 | return out 72 | 73 | where 74 | cmdAndArgs : m (String × Array String) := do 75 | match Shell.shlex command.getString with 76 | | .error e => throwErrorAt command e 77 | | .ok components => 78 | if h : components.size = 0 then 79 | throwErrorAt command "No command provided" 80 | else 81 | return (components[0], components.extract 1) 82 | 83 | 84 | def commandOut (container : Ident) (command : StrLit) : m String := do 85 | let c ← requireContainer container 86 | if let some out := c.outputs[command.getString.trimAscii.copy]? then 87 | return out 88 | else throwErrorAt command "Output not found: {indentD command}" 89 | 90 | def fileContents (container : Ident) (file : StrLit) : m String := do 91 | let c ← requireContainer container 92 | let filename := c.workingDirectory / "examples" / file.getString 93 | unless (← filename.pathExists) do 94 | throwErrorAt file "{filename} does not exist" 95 | if (← filename.isDir) then 96 | throwErrorAt file "{filename} is a directory" 97 | IO.FS.readFile filename 98 | 99 | 100 | end Commands 101 | -------------------------------------------------------------------------------- /book/lakefile.lean: -------------------------------------------------------------------------------- 1 | import Lake 2 | 3 | open System Lake DSL 4 | 5 | package book where 6 | version := v!"0.1.0" 7 | leanOptions := 8 | #[⟨`weak.verso.examples.suggest, true⟩, 9 | ⟨`weak.linter.verso.manual.headerTags, true⟩, 10 | ⟨`weak.verso.externalExamples.suppressedNamespaces, 11 | "A Adding Agh Argh Almost Alt AltPos AndDef AndThen AppendOverloads ApplicativeOptionLaws ApplicativeOptionLaws2 ApplicativeToFunctor Apply Argh AutoImpl B BadUnzip BetterHPlus BetterPlicity Blurble Both Busted C CheckFunctorPair Class Cls Cmp Connectives Cont Ctor D Decide Demo Desugared Details DirTree DirTree.Old DirTree.Readerish DirTree.T Double EEE EarlyReturn Eff Errs Eta Evaluator Even Ex Exercises Explicit ExplicitParens Extra Extras F F1 F2 Fake FakeAlternative FakeCoe FakeExcept FakeFunctor FakeMonad FakeOrElse FakeSeqRight FancyDo FastPos FinDef Finny Fixity Floop ForMIO Foo Foo2 Four FourPointFive Golf Golf' Guard H HelloName1 HelloName2 HelloName3 Huh IdentMonad Impl Improved Inductive Inflexible IterSub L Lawful ListExtras Loops Loops.Cont M MMM Main1 Main2 Main3 Match MatchDef Mine Modify MonadApplicative MonadApplicativeDesugar MonadApplicativeProof1 MonadApplicativeProof2 MonadApplicativeProof3 MonadApplicativeProof4 MonadLaws Monadicish Monads.Err Monads.Option Monads.State Monads.Writer More MoreClear MoreMonadic Mut MyList1 MyList15 MyList3 MyListStuff MyMonadExcept MyMonadLift MySum NRT NT NatLits Nested New NoTac Non Numbering Numbering.Short Old One OneAttempt Oooops Ooops Oops Opt Option OrElse Orders Original Other OverloadedBits OverloadedInt OwnInstances Partial PipelineEx PointStuff ProblematicHPlus Prod Proofs PropStuff Provisional Provisional2 R Ranges Readerish ReallyNoTypes Reorder SameDo SeqCounterexample SeqLeftSugar SeqRightSugar Ser Short St StEx StdLibNoUni Str StructNotation Structed SubtypeDemo SugaryOrElse Sum T TTT Tactical TailRec Temp ThenDoUnless Three Transformed Two U Up UseList VariousTypes Verbose Wak Whatevs WithAndThen WithDo WithFor WithInfix WithMatch WithPattern"⟩] 12 | 13 | require verso from git "https://github.com/leanprover/verso.git"@"main" 14 | 15 | private def examplePath : System.FilePath := "../examples" 16 | 17 | private def lakeVars := 18 | #["LAKE", "LAKE_HOME", "LAKE_PKG_URL_MAP", "LAKE_CACHE_DIR", 19 | "LEAN", "LEAN_SYSROOT", "LEAN_AR", "LEAN_PATH", "LEAN_SRC_PATH", 20 | "LEAN_GITHASH", 21 | "ELAN_TOOLCHAIN", "DYLD_LIBRARY_PATH", "LD_LIBRARY_PATH"] 22 | 23 | private def fixPath (path : System.SearchPath) : String := 24 | path |>.map (·.toString) |>.filter (!·.contains ".lake") |> System.SearchPath.separator.toString.intercalate 25 | 26 | input_dir examples where 27 | path := examplePath 28 | text := true 29 | filter := .extension "lean" 30 | 31 | input_dir exampleBinaries where 32 | path := examplePath / ".lake" / "build" / "bin" 33 | text := false 34 | 35 | 36 | target buildExamples (pkg) : Unit := do 37 | let exs ← examples.fetch 38 | let exBins ← exampleBinaries.fetch 39 | let toolchainFile := examplePath / "lean-toolchain" 40 | let toolchain ← IO.FS.readFile toolchainFile 41 | let toolchain := toolchain.trimAscii |>.dropPrefix "leanprover/lean4:" |>.dropPrefix "v" |>.copy 42 | addPureTrace toolchain 43 | exBins.bindM fun binFiles => do 44 | for file in binFiles do 45 | if file.extension.isNone || file.extension.isEqSome System.FilePath.exeExtension then 46 | addTrace (← computeTrace file) 47 | exs.mapM fun exFiles => do 48 | let mut list := "" 49 | for file in exFiles do 50 | addTrace (← computeTrace <| TextFilePath.mk file) 51 | list := list ++ s!"{file}\n" 52 | buildFileUnlessUpToDate' (pkg.buildDir / "examples-built") (text := true) do 53 | Lake.logInfo s!"Building examples in {examplePath}" 54 | let mut out := "" 55 | let path := fixPath (← getSearchPath "PATH") 56 | out := out ++ (← captureProc { 57 | cmd := "elan", 58 | args := #["run", "--install", toolchain, "lake", "build"], 59 | cwd := examplePath, 60 | env := lakeVars.map (·, none) ++ #[("PATH", some path)] 61 | }) 62 | out := out ++ (← captureProc { 63 | cmd := "elan", 64 | args := #["run", "--install", toolchain, "lake", "build", "subverso-extract-mod"], 65 | cwd := examplePath, 66 | env := lakeVars.map (·, none) ++ #[("PATH", some path)] 67 | }) 68 | IO.FS.createDirAll pkg.buildDir 69 | IO.FS.writeFile (pkg.buildDir / "examples-built") (list ++ "--- Output ---\n" ++ out) 70 | 71 | target syncBuildExamples : Unit := do 72 | .pure <$> (← buildExamples.fetch).await 73 | 74 | lean_lib FPLean where 75 | needs := #[syncBuildExamples] 76 | 77 | @[default_target] lean_exe «fp-lean» where root := `Main 78 | -------------------------------------------------------------------------------- /book/static/fonts/source-sans/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2010-2024 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries. 2 | 3 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 4 | 5 | This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL 6 | 7 | 8 | ----------------------------------------------------------- 9 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 10 | ----------------------------------------------------------- 11 | 12 | PREAMBLE 13 | The goals of the Open Font License (OFL) are to stimulate worldwide 14 | development of collaborative font projects, to support the font creation 15 | efforts of academic and linguistic communities, and to provide a free and 16 | open framework in which fonts may be shared and improved in partnership 17 | with others. 18 | 19 | The OFL allows the licensed fonts to be used, studied, modified and 20 | redistributed freely as long as they are not sold by themselves. The 21 | fonts, including any derivative works, can be bundled, embedded, 22 | redistributed and/or sold with any software provided that any reserved 23 | names are not used by derivative works. The fonts and derivatives, 24 | however, cannot be released under any other type of license. The 25 | requirement for fonts to remain under this license does not apply 26 | to any document created using the fonts or their derivatives. 27 | 28 | DEFINITIONS 29 | "Font Software" refers to the set of files released by the Copyright 30 | Holder(s) under this license and clearly marked as such. This may 31 | include source files, build scripts and documentation. 32 | 33 | "Reserved Font Name" refers to any names specified as such after the 34 | copyright statement(s). 35 | 36 | "Original Version" refers to the collection of Font Software components as 37 | distributed by the Copyright Holder(s). 38 | 39 | "Modified Version" refers to any derivative made by adding to, deleting, 40 | or substituting -- in part or in whole -- any of the components of the 41 | Original Version, by changing formats or by porting the Font Software to a 42 | new environment. 43 | 44 | "Author" refers to any designer, engineer, programmer, technical 45 | writer or other person who contributed to the Font Software. 46 | 47 | PERMISSION & CONDITIONS 48 | Permission is hereby granted, free of charge, to any person obtaining 49 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 50 | redistribute, and sell modified and unmodified copies of the Font 51 | Software, subject to the following conditions: 52 | 53 | 1) Neither the Font Software nor any of its individual components, 54 | in Original or Modified Versions, may be sold by itself. 55 | 56 | 2) Original or Modified Versions of the Font Software may be bundled, 57 | redistributed and/or sold with any software, provided that each copy 58 | contains the above copyright notice and this license. These can be 59 | included either as stand-alone text files, human-readable headers or 60 | in the appropriate machine-readable metadata fields within text or 61 | binary files as long as those fields can be easily viewed by the user. 62 | 63 | 3) No Modified Version of the Font Software may use the Reserved Font 64 | Name(s) unless explicit written permission is granted by the corresponding 65 | Copyright Holder. This restriction only applies to the primary font name as 66 | presented to the users. 67 | 68 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 69 | Software shall not be used to promote, endorse or advertise any 70 | Modified Version, except to acknowledge the contribution(s) of the 71 | Copyright Holder(s) and the Author(s) or with their explicit written 72 | permission. 73 | 74 | 5) The Font Software, modified or unmodified, in part or in whole, 75 | must be distributed entirely under this license, and must not be 76 | distributed under any other license. The requirement for fonts to 77 | remain under this license does not apply to any document created 78 | using the Font Software. 79 | 80 | TERMINATION 81 | This license becomes null and void if any of the above conditions are 82 | not met. 83 | 84 | DISCLAIMER 85 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 86 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 87 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 88 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 89 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 90 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 91 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 92 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 93 | OTHER DEALINGS IN THE FONT SOFTWARE. 94 | -------------------------------------------------------------------------------- /book/static/fonts/noto-sans-mono/OFL.txt: -------------------------------------------------------------------------------- 1 | Copyright 2022 The Noto Project Authors (https://github.com/notofonts/latin-greek-cyrillic) 2 | 3 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 4 | This license is copied below, and is also available with a FAQ at: 5 | https://openfontlicense.org 6 | 7 | 8 | ----------------------------------------------------------- 9 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 10 | ----------------------------------------------------------- 11 | 12 | PREAMBLE 13 | The goals of the Open Font License (OFL) are to stimulate worldwide 14 | development of collaborative font projects, to support the font creation 15 | efforts of academic and linguistic communities, and to provide a free and 16 | open framework in which fonts may be shared and improved in partnership 17 | with others. 18 | 19 | The OFL allows the licensed fonts to be used, studied, modified and 20 | redistributed freely as long as they are not sold by themselves. The 21 | fonts, including any derivative works, can be bundled, embedded, 22 | redistributed and/or sold with any software provided that any reserved 23 | names are not used by derivative works. The fonts and derivatives, 24 | however, cannot be released under any other type of license. The 25 | requirement for fonts to remain under this license does not apply 26 | to any document created using the fonts or their derivatives. 27 | 28 | DEFINITIONS 29 | "Font Software" refers to the set of files released by the Copyright 30 | Holder(s) under this license and clearly marked as such. This may 31 | include source files, build scripts and documentation. 32 | 33 | "Reserved Font Name" refers to any names specified as such after the 34 | copyright statement(s). 35 | 36 | "Original Version" refers to the collection of Font Software components as 37 | distributed by the Copyright Holder(s). 38 | 39 | "Modified Version" refers to any derivative made by adding to, deleting, 40 | or substituting -- in part or in whole -- any of the components of the 41 | Original Version, by changing formats or by porting the Font Software to a 42 | new environment. 43 | 44 | "Author" refers to any designer, engineer, programmer, technical 45 | writer or other person who contributed to the Font Software. 46 | 47 | PERMISSION & CONDITIONS 48 | Permission is hereby granted, free of charge, to any person obtaining 49 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 50 | redistribute, and sell modified and unmodified copies of the Font 51 | Software, subject to the following conditions: 52 | 53 | 1) Neither the Font Software nor any of its individual components, 54 | in Original or Modified Versions, may be sold by itself. 55 | 56 | 2) Original or Modified Versions of the Font Software may be bundled, 57 | redistributed and/or sold with any software, provided that each copy 58 | contains the above copyright notice and this license. These can be 59 | included either as stand-alone text files, human-readable headers or 60 | in the appropriate machine-readable metadata fields within text or 61 | binary files as long as those fields can be easily viewed by the user. 62 | 63 | 3) No Modified Version of the Font Software may use the Reserved Font 64 | Name(s) unless explicit written permission is granted by the corresponding 65 | Copyright Holder. This restriction only applies to the primary font name as 66 | presented to the users. 67 | 68 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 69 | Software shall not be used to promote, endorse or advertise any 70 | Modified Version, except to acknowledge the contribution(s) of the 71 | Copyright Holder(s) and the Author(s) or with their explicit written 72 | permission. 73 | 74 | 5) The Font Software, modified or unmodified, in part or in whole, 75 | must be distributed entirely under this license, and must not be 76 | distributed under any other license. The requirement for fonts to 77 | remain under this license does not apply to any document created 78 | using the Font Software. 79 | 80 | TERMINATION 81 | This license becomes null and void if any of the above conditions are 82 | not met. 83 | 84 | DISCLAIMER 85 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 86 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 87 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 88 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 89 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 90 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 91 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 92 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 93 | OTHER DEALINGS IN THE FONT SOFTWARE. 94 | -------------------------------------------------------------------------------- /book/static/fonts/source-serif/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2014 - 2023 Adobe (http://www.adobe.com/), with Reserved Font Name ‘Source’. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries. 2 | 3 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 4 | 5 | This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL 6 | 7 | 8 | ----------------------------------------------------------- 9 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 10 | ----------------------------------------------------------- 11 | 12 | PREAMBLE 13 | The goals of the Open Font License (OFL) are to stimulate worldwide 14 | development of collaborative font projects, to support the font creation 15 | efforts of academic and linguistic communities, and to provide a free and 16 | open framework in which fonts may be shared and improved in partnership 17 | with others. 18 | 19 | The OFL allows the licensed fonts to be used, studied, modified and 20 | redistributed freely as long as they are not sold by themselves. The 21 | fonts, including any derivative works, can be bundled, embedded, 22 | redistributed and/or sold with any software provided that any reserved 23 | names are not used by derivative works. The fonts and derivatives, 24 | however, cannot be released under any other type of license. The 25 | requirement for fonts to remain under this license does not apply 26 | to any document created using the fonts or their derivatives. 27 | 28 | DEFINITIONS 29 | "Font Software" refers to the set of files released by the Copyright 30 | Holder(s) under this license and clearly marked as such. This may 31 | include source files, build scripts and documentation. 32 | 33 | "Reserved Font Name" refers to any names specified as such after the 34 | copyright statement(s). 35 | 36 | "Original Version" refers to the collection of Font Software components as 37 | distributed by the Copyright Holder(s). 38 | 39 | "Modified Version" refers to any derivative made by adding to, deleting, 40 | or substituting -- in part or in whole -- any of the components of the 41 | Original Version, by changing formats or by porting the Font Software to a 42 | new environment. 43 | 44 | "Author" refers to any designer, engineer, programmer, technical 45 | writer or other person who contributed to the Font Software. 46 | 47 | PERMISSION & CONDITIONS 48 | Permission is hereby granted, free of charge, to any person obtaining 49 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 50 | redistribute, and sell modified and unmodified copies of the Font 51 | Software, subject to the following conditions: 52 | 53 | 1) Neither the Font Software nor any of its individual components, 54 | in Original or Modified Versions, may be sold by itself. 55 | 56 | 2) Original or Modified Versions of the Font Software may be bundled, 57 | redistributed and/or sold with any software, provided that each copy 58 | contains the above copyright notice and this license. These can be 59 | included either as stand-alone text files, human-readable headers or 60 | in the appropriate machine-readable metadata fields within text or 61 | binary files as long as those fields can be easily viewed by the user. 62 | 63 | 3) No Modified Version of the Font Software may use the Reserved Font 64 | Name(s) unless explicit written permission is granted by the corresponding 65 | Copyright Holder. This restriction only applies to the primary font name as 66 | presented to the users. 67 | 68 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 69 | Software shall not be used to promote, endorse or advertise any 70 | Modified Version, except to acknowledge the contribution(s) of the 71 | Copyright Holder(s) and the Author(s) or with their explicit written 72 | permission. 73 | 74 | 5) The Font Software, modified or unmodified, in part or in whole, 75 | must be distributed entirely under this license, and must not be 76 | distributed under any other license. The requirement for fonts to 77 | remain under this license does not apply to any document created 78 | using the Font Software. 79 | 80 | TERMINATION 81 | This license becomes null and void if any of the above conditions are 82 | not met. 83 | 84 | DISCLAIMER 85 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 86 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 87 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 88 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 89 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 90 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 91 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 92 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 93 | OTHER DEALINGS IN THE FONT SOFTWARE. 94 | --------------------------------------------------------------------------------