Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gelisam/linear-examples
Example uses of linear types
https://github.com/gelisam/linear-examples
Last synced: 13 days ago
JSON representation
Example uses of linear types
- Host: GitHub
- URL: https://github.com/gelisam/linear-examples
- Owner: gelisam
- Created: 2017-11-27T04:04:35.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-06-25T14:28:44.000Z (over 4 years ago)
- Last Synced: 2024-10-25T09:29:59.978Z (21 days ago)
- Language: Haskell
- Homepage:
- Size: 24.4 KB
- Stars: 42
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# linear-examples
The goal is to write a few example libraries using [tweag's implementation of linear types for GHC](https://github.com/tweag/ghc/tree/linear-types#readme), in order to fuel the [discussion page about the linear types proposal](https://github.com/ghc-proposals/ghc-proposals/pull/91#issuecomment-346721678).
So far, there is only one example, a Haskell implementation of [my blog post about watertight 3D models](https://www.spiria.com/en/blog/desktop-software/making-non-manifold-models-unrepresentable). In a nutshell, the goal is to prevent holes in 3D surfaces by making sure that every edge is bound by exactly two faces. This is accomplished by guaranteeing that each edge is used exactly twice, which is in turn accomplished by generating two co-edges at a time and using linear types to make sure that each one is used by exactly one face. So the following compiles:
makeWatertight3dModel $ do
Unrestricted pA <- addPoint (1,2,3)
Unrestricted pB <- addPoint (4,5,6)
Unrestricted pC <- addPoint (7,8,9)
(coedgeAB, coedgeBA) <- addCoEdges pA pB
(coedgeBC, coedgeCB) <- addCoEdges pB pC
(coedgeCA, coedgeAC) <- addCoEdges pC pA
addFace [coedgeAB, coedgeBC, coedgeCA]
addFace [coedgeAC, coedgeCB, coedgeBA]But if the last line is commented out, the compiler complains that many co-edges are never used, which is exactly what we want since that means the corresponding edges are bordering a hole in the surface.
## Build instructions
[Build ghc-HEAD](https://ghc.dev/) (or use ghc-10.12 if it's out by the time you
read this), then build linear-watertight:$ cabal v2-build linear-watertight