diff --git a/.ghci b/.ghci deleted file mode 100644 index e53ed721..00000000 --- a/.ghci +++ /dev/null @@ -1,2 +0,0 @@ -:set -isrc -:seti -XOverloadedStrings diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index f24134fb..06534697 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -1,52 +1,52 @@ -name: github-action - -on: [push, pull_request] - -jobs: - build: - strategy: - fail-fast: false - matrix: - ghc: ['8.4.4', '8.6.5', '8.8.4', '8.10.7', '9.0.1', '9.2.5', '9.4.5', '9.6.1', '9.8.2', '9.10.1', '9.12.1'] - os: ['ubuntu-latest', 'macos-latest'] - runs-on: ${{ matrix.os }} - - name: GHC ${{ matrix.ghc }} on ${{ matrix.os }} - steps: - - - uses: actions/checkout@v3 - - - uses: haskell/actions/setup@v2 - with: - ghc-version: ${{ matrix.ghc }} - cabal-version: '3.10.3.0' - - - name: Cache - uses: actions/cache@v3 - env: - cache-name: cache-cabal - with: - path: ~/.cabal - key: ${{ runner.os }}-${{ matrix.ghc }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.ghc }}-build-${{ env.cache-name }}- - ${{ runner.os }}-${{ matrix.ghc }}-build- - ${{ runner.os }}-${{ matrix.ghc }}- - ${{ runner.os }} - - - name: Install dependencies - run: | - cabal update - cabal build --only-dependencies --enable-tests --enable-benchmarks - - - name: Build - run: cabal build --enable-tests --enable-benchmarks all - - - name: Run tests - # We don't run hlint tests, because different versions of hlint have different suggestions, and we don't want to worry about satisfying them all. - run: cabal test --enable-tests -f-hlint all - - - if: matrix.ghc != '8.4.4' - # docs aren't built on ghc 8.4.4 because some dependency docs don't build on older GHCs - name: Build Docs - run: cabal haddock +#name: github-action +# +#on: [push, pull_request] +# +#jobs: +# build: +# strategy: +# fail-fast: false +# matrix: +# ghc: ['8.4.4', '8.6.5', '8.8.4', '8.10.7', '9.0.1', '9.2.5', '9.4.5', '9.6.1', '9.8.2', '9.10.1', '9.12.1'] +# os: ['ubuntu-latest', 'macos-latest'] +# runs-on: ${{ matrix.os }} +# +# name: GHC ${{ matrix.ghc }} on ${{ matrix.os }} +# steps: +# +# - uses: actions/checkout@v3 +# +# - uses: haskell/actions/setup@v2 +# with: +# ghc-version: ${{ matrix.ghc }} +# cabal-version: '3.10.3.0' +# +# - name: Cache +# uses: actions/cache@v3 +# env: +# cache-name: cache-cabal +# with: +# path: ~/.cabal +# key: ${{ runner.os }}-${{ matrix.ghc }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }} +# restore-keys: | +# ${{ runner.os }}-${{ matrix.ghc }}-build-${{ env.cache-name }}- +# ${{ runner.os }}-${{ matrix.ghc }}-build- +# ${{ runner.os }}-${{ matrix.ghc }}- +# ${{ runner.os }} +# +# - name: Install dependencies +# run: | +# cabal update +# cabal build --only-dependencies --enable-tests --enable-benchmarks +# +# - name: Build +# run: cabal build --enable-tests --enable-benchmarks all +# +# - name: Run tests +# # We don't run hlint tests, because different versions of hlint have different suggestions, and we don't want to worry about satisfying them all. +# run: cabal test --enable-tests -f-hlint all +# +# - if: matrix.ghc != '8.4.4' +# # docs aren't built on ghc 8.4.4 because some dependency docs don't build on older GHCs +# name: Build Docs +# run: cabal haddock diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 00000000..f1b46124 --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,59 @@ +name: nix + +on: + pull_request: + push: + branches: [ develop, master ] + +env: + # The nix every job installs. release.nix evaluates through + # import-from-derivation. + EXTRA_NIX_CONFIG: | + experimental-features = nix-command flakes + allow-import-from-derivation = true + extra-substituters = https://cache.iog.io https://nixcache.reflex-frp.org + extra-trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI= + +jobs: + # The `-A` path of every cell of release.nix, for the smoke matrix. The + # parts state their cells from their matrix lists, so this evaluation + # builds nothing. + nix-attrs: + # A pull request whose head is `develop` or `master` in this repository + # gets the push run for the same commit, so its own run is skipped. The + # jobs below need this one, so the skip covers the whole run. The branch + # list repeats the push trigger's: an expression cannot read it. + if: >- + github.event_name == 'push' + || github.event.pull_request.head.repo.full_name != github.repository + || !contains(fromJSON('["develop", "master"]'), github.head_ref) + runs-on: ubuntu-latest + outputs: + paths: ${{ steps.eval.outputs.paths }} + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v31 + with: + extra_nix_config: ${{ env.EXTRA_NIX_CONFIG }} + - name: Evaluate release.nix -A attr-paths + id: eval + run: | + paths=$(nix-instantiate --eval --strict --json --read-write-mode release.nix -A attr-paths) + echo "paths=$paths" >> "$GITHUB_OUTPUT" + + # One build per cell, each on its own runner. A broken cell cancels no + # other build. + nix-smoke: + needs: nix-attrs + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + attr: ${{ fromJSON(needs.nix-attrs.outputs.paths) }} + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v31 + with: + extra_nix_config: ${{ env.EXTRA_NIX_CONFIG }} + - name: Build release.nix -A ${{ matrix.attr }} + run: nix-build release.nix -A ${{ matrix.attr }} --keep-going --no-out-link diff --git a/.gitignore b/.gitignore index 88ce9236..f6a91c86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ dist +result +result-* cabal.sandbox.config cabal.project.local .cabal-sandbox/ diff --git a/.hlint.yaml b/.hlint.yaml new file mode 100755 index 00000000..61b5aec3 --- /dev/null +++ b/.hlint.yaml @@ -0,0 +1,341 @@ +#! /usr/bin/env nix +#! nix shell github:obsidiansystems/style.hs#hlint --command sh -c ``hlint --hint "$1" "${@:2}"`` sh + +# The Obsidian Systems Haskell style, for hlint. See STYLE.md for the +# reasoning, and fourmolu.yaml for the formatting half of the same style. +# +# hlint is a linter, not a formatter, so this config complements fourmolu +# rather than competing with it: fourmolu handles layout, hlint handles the +# rules about *what* you write. Both can run over the same file. +# +# Note that hlint always loads its own built-in hints first, whatever you pass +# on the command line. A config like this one is therefore purely additive: it +# can turn extra hints on, restrict what you're allowed to use, and `ignore` +# built-ins, but it can never start from a blank slate. + +# STYLE.md, "Safety: avoid partial functions", the rule we feel most strongly +# about. +# +# hlint ships a `partial` group covering much of this, but we spell the list +# out instead. A `functions` restriction matches an identifier in every +# syntactic position, so it catches `map head` and `(!! 3)` as well as +# `head xs`; the group's rewrite rules only fire on applied uses, and let a +# bare `map head` through entirely. Enabling both would double-report every +# applied use, so it is one or the other. +# +# The list is the standard one STYLE.md points at. Functions that are only +# partial on infinite lists are deliberately absent, as are the near-unavoidable +# ones (div, mod, quot, succ, toEnum) that hlint's `partial-strict` group bans. +# +# The names are qualified, which matters. hlint matches an unqualified name +# against every module it could have come from, so a bare `head` also bans +# `NonEmpty.head` — which is total, and is precisely what you are supposed to +# reach for once you have a NonEmpty. The same goes for `last`, `tail`, `init`, +# `maximum` and `minimum`. Qualifying each entry bans the partial version and +# leaves the NonEmpty (and Foldable1) counterparts alone. +# +# The cost of qualifying is that every partial source has to be spelled out, so +# Text and ByteString appear here too: their `head`/`last`/`tail`/`init` are +# just as partial as the list ones. `!!` and `fromJust` stay unqualified +# because they are partial wherever they come from, NonEmpty included. +- functions: + - name: + - Prelude.head + - Prelude.last + - Prelude.tail + - Prelude.init + - Data.List.head + - Data.List.last + - Data.List.tail + - Data.List.init + - Prelude.foldr1 + - Prelude.foldl1 + - Prelude.maximum + - Prelude.minimum + - Data.List.foldr1 + - Data.List.foldl1 + - Data.List.maximum + - Data.List.minimum + - Data.List.maximumBy + - Data.List.minimumBy + - Data.Foldable.foldr1 + - Data.Foldable.foldl1 + - Data.Foldable.maximum + - Data.Foldable.minimum + - Data.Foldable.maximumBy + - Data.Foldable.minimumBy + - Data.Text.head + - Data.Text.last + - Data.Text.tail + - Data.Text.init + - Data.Text.Lazy.head + - Data.Text.Lazy.last + - Data.Text.Lazy.tail + - Data.Text.Lazy.init + - Data.ByteString.head + - Data.ByteString.last + - Data.ByteString.tail + - Data.ByteString.init + - Data.ByteString.Char8.head + - Data.ByteString.Char8.last + - Data.ByteString.Char8.tail + - Data.ByteString.Char8.init + - Data.ByteString.Lazy.head + - Data.ByteString.Lazy.last + - Data.ByteString.Lazy.tail + - Data.ByteString.Lazy.init + - "!!" + - fromJust + - Data.List.NonEmpty.fromList + within: [] + message: 'STYLE.md: partial function. It fails far from the mistake that caused it, with a message that tells you nothing.' + - name: undefined + within: [] + message: 'STYLE.md: use `error` with a source location and a comment saying why the branch is unreachable.' + - name: ["Data.Map.!", "Data.Map.Strict.!", "Data.Map.Monoidal.!"] + within: [] + message: 'STYLE.md: partial. Use `Map.lookup`, or `Map.findWithDefault`.' + - name: [Data.Text.Encoding.decodeUtf8, Data.Text.Lazy.Encoding.decodeUtf8] + within: [] + message: 'STYLE.md: partial. Use `decodeUtf8With lenientDecode`.' + - name: read + within: [] + message: 'STYLE.md: partial. Use `readMaybe`.' + +# STYLE.md, "Extensions we avoid". Each of these removes a way for code to go +# wrong quietly. +- extensions: + - name: [RecordWildCards, NamedFieldPuns] + within: [] + message: 'STYLE.md: a binding site that does not name what it binds makes scoping hard to trace.' + - name: DeriveAnyClass + within: [] + message: 'STYLE.md: it does not guarantee the methods get an implementation, which becomes a runtime crash.' + +# STYLE.md, "Imports". `**` rather than `*`: hlint maps `.` to `/` and matches +# with glob semantics, so a single `*` would not match `Data.Text`. +# +# Exact-name and `**` rules compose, so a module listed below is still checked +# for post-qualification. When both are wrong hlint reports the alias first, +# and the qualification warning appears once that is fixed. +- modules: + - name: "**" + qualifiedStyle: post + message: 'STYLE.md: post-qualified imports line the module names up in the same column. Needs ImportQualifiedPost, on by default since GHC 9.6.' + - {name: Data.Text, as: T} + - {name: Data.Map, as: Map} + - {name: Data.Map.Monoidal, as: MMap} + - {name: Data.Set, as: Set} + - {name: Data.ByteString, as: BS} + - {name: Data.ByteString.Lazy, as: LBS} + +# STYLE.md, "Formatting": append with `<>`, not `++`. They behave identically +# on lists, but `<>` leaves the door open to changing your sequence type later. +# +# Always on, so it holds without the group below. hlint's own generalise +# carries this rule too, so enabling that group reports a `++` twice. +- warn: {lhs: a ++ b, rhs: a <> b, name: "Use <>"} + +# Preferring the more general of two functions that already do the same thing, +# so loosening a type later costs no call site. Off by default, because a +# codebase adopts this on its own schedule: +# +# hlint --with-group=generalise src/ +# +# The name is hlint's own group, so these rules join its built-in members +# rather than replace them. +- group: + name: generalise + enabled: false + rules: + # `<>` is the Semigroup method, where `mappend` is the Monoid one that + # duplicates it. + - warn: {lhs: mappend, rhs: "(<>)", name: "Use <>"} + + # `pure`, `liftA2` and `<*>` ask for an Applicative, where the Monad-only + # spellings beside them are the older duplicates. `liftM` is absent + # because hlint suggests `fmap` for it already, and a second rule would + # report it twice. + - warn: {lhs: return, rhs: pure, name: "Use pure"} + - warn: {lhs: liftM2, rhs: liftA2, name: "Use liftA2"} + - warn: {lhs: ap, rhs: "(<*>)", name: "Use <*>"} + + # The Alternative spellings, which the MonadPlus ones duplicate. + - warn: {lhs: msum, rhs: asum, name: "Use asum"} + - warn: {lhs: mplus, rhs: "(<|>)", name: "Use <|>"} + - warn: {lhs: mzero, rhs: empty, name: "Use empty"} + + # The Traversable spellings, which ask for an Applicative where the `M` + # spellings ask for a Monad. + - warn: {lhs: mapM, rhs: traverse, name: "Use traverse"} + - warn: {lhs: mapM_, rhs: traverse_, name: "Use traverse_"} + - warn: {lhs: forM, rhs: for, name: "Use for"} + - warn: {lhs: forM_, rhs: for_, name: "Use for_"} + + # The Foldable spellings, which take any container where these take a + # list. + - warn: {lhs: mconcat, rhs: fold, name: "Use fold"} + - warn: {lhs: concat, rhs: fold, name: "Use fold"} + - warn: {lhs: concatMap, rhs: foldMap, name: "Use foldMap"} + + # A Map is a Functor and a Foldable, so it needs no spellings of its own. + # Qualified, because a bare `map` or `elems` would match far more than a + # Map. + - warn: {lhs: Data.Map.map, rhs: fmap, name: "Use fmap"} + - warn: {lhs: Data.Map.Strict.map, rhs: fmap, name: "Use fmap"} + - warn: {lhs: Data.Map.Monoidal.map, rhs: fmap, name: "Use fmap"} + - warn: {lhs: Data.Map.elems, rhs: toList, name: "Use toList"} + - warn: {lhs: Data.Map.Strict.elems, rhs: toList, name: "Use toList"} + - warn: {lhs: Data.Map.Monoidal.elems, rhs: toList, name: "Use toList"} + +# Built-in hints that contradict STYLE.md. +# +# `Use camelCase` fires on every `myRecord_fieldName` and `MySumType_Ctor`, +# i.e. on exactly the naming convention STYLE.md mandates. +- ignore: {name: Use camelCase} + +# The rest suggest a partial function we just banned, so they fire alongside +# "Avoid restricted function" and push the reader toward the very thing the +# restriction above forbids: `x !! 0` -> `head x`, `head (sort x)` -> +# `minimum x`, `head (reverse x)` -> `last x`, and so on. +- ignore: {name: Use head} +- ignore: {name: Use last} +- ignore: {name: Use init} +- ignore: {name: Use tail} +- ignore: {name: Use minimum} +- ignore: {name: Use maximum} +- ignore: {name: Use foldr1} +- ignore: {name: Use foldl1} + +# `concat [a, b]` -> `a ++ b`, which contradicts the `<>` rule above. +- ignore: {name: Use ++} + +# `when (not p)` -> `unless p`. Both spellings are fine, so this is left to the +# author: a `when (not p)` sitting next to a `when q` reads as one parallel +# pair, where swapping in `unless` makes the reader match up two different +# words and a dropped negation to see that the guards are related. +- ignore: {name: Use unless} + +# `\s -> "pre" <> s` -> `("pre" <>)`. Naming the argument is often the clearer +# of the two, and which one wins is a judgement call the linter is not well +# placed to make, so leave it to the author. +# +# Note this gives up the other half of the hint, `\x -> f x` -> `f`, which is a +# plain eta-reduction and is usually an improvement. `Eta reduce` still covers +# that shape at the top level of a definition; only lambdas nested inside an +# expression go unremarked. +- ignore: {name: Avoid lambda} + +# `and [a, b]` -> `a && b`, and `or [a, b]` -> `a || b`. Both spellings are +# correct, so the author chooses. The list form gives each condition its own +# line. A long list stays readable. A new condition is a one-line diff. The +# hint fires at every list length, so it reports the list form everywhere. +- ignore: {name: "Use &&"} +- ignore: {name: "Use ||"} + +# Left on deliberately, so nobody "fixes" them later: +# +# - The `dollar` group stays off. It rewrites `a $ b $ c` to `a . b $ c`, but +# STYLE.md prefers `$` to `.` when either would read the same. +# - `Redundant $` stays on. It only fires when the argument is atomic (`f $ x`), +# so it does not conflict with "prefer `$` to trailing parentheses". +# - `Use lambda-case` stays on. It matches STYLE.md's "Prefer `case` to multiple +# clauses", whose preferred form is `\case`. + +# Extensions Obsidian projects turn on in the cabal file. hlint does not read +# cabal files, so without this it misparses anything that relies on them: a +# module with no per-module LANGUAGE pragmas is exactly the case the shared +# cabal preamble is meant to produce, and hlint would choke on the first +# quasiquote or multiline string. +# +# This mirrors the preamble's `default-extensions`, which is a superset of +# STYLE.md's "Extensions we'd turn on by default". That is deliberate: the list +# is here only to make hlint parse what GHC already accepts, not to endorse +# every entry. ImportQualifiedPost is required by the import rule above, and +# the No* entries match the extensions the `extensions` restriction bans. +- arguments: + - -XAllowAmbiguousTypes + - -XApplicativeDo + - -XBangPatterns + - -XBinaryLiterals + - -XBlockArguments + - -XConstrainedClassMethods + - -XConstraintKinds + - -XDataKinds + - -XDefaultSignatures + - -XDeriveDataTypeable + - -XDeriveFoldable + - -XDeriveFunctor + - -XDeriveGeneric + - -XDeriveLift + - -XDeriveTraversable + - -XDerivingStrategies + - -XDerivingVia + - -XDisambiguateRecordFields + - -XDoAndIfThenElse + - -XDuplicateRecordFields + - -XEmptyCase + - -XEmptyDataDecls + - -XEmptyDataDeriving + - -XExistentialQuantification + - -XExplicitForAll + - -XExplicitNamespaces + - -XExtendedDefaultRules + - -XFlexibleContexts + - -XFlexibleInstances + - -XFunctionalDependencies + - -XGADTs + - -XGeneralizedNewtypeDeriving + - -XHexFloatLiterals + - -XImportQualifiedPost + - -XImpredicativeTypes + - -XInstanceSigs + - -XKindSignatures + - -XLambdaCase + - -XLexicalNegation + - -XLiberalTypeSynonyms + - -XMonadComprehensions + - -XMultilineStrings + - -XMultiParamTypeClasses + - -XMultiWayIf + - -XNamedDefaults + - -XNegativeLiterals + - -XNoDeriveAnyClass + - -XNoNamedFieldPuns + - -XNoRecordWildCards + - -XNumericUnderscores + - -XOrPatterns + - -XOverloadedLabels + - -XOverloadedLists + - -XOverloadedRecordDot + - -XOverloadedStrings + - -XPackageImports + - -XParallelListComp + - -XPartialTypeSignatures + - -XPatternGuards + - -XPatternSynonyms + - -XPolyKinds + - -XPostfixOperators + - -XQualifiedDo + - -XQuantifiedConstraints + - -XQuasiQuotes + - -XRankNTypes + - -XRecursiveDo + - -XRequiredTypeArguments + - -XRoleAnnotations + - -XScopedTypeVariables + - -XStandaloneDeriving + - -XStandaloneKindSignatures + - -XTemplateHaskell + - -XTemplateHaskellQuotes + - -XTransformListComp + - -XTupleSections + - -XTypeApplications + - -XTypeData + - -XTypeFamilies + - -XTypeFamilyDependencies + - -XTypeOperators + - -XTypeSynonymInstances + - -XUndecidableInstances + - -XUnicodeSyntax + - -XViewPatterns diff --git a/.stylish-haskell.yaml b/.stylish-haskell.yaml deleted file mode 100644 index e9caef3c..00000000 --- a/.stylish-haskell.yaml +++ /dev/null @@ -1,153 +0,0 @@ -# stylish-haskell configuration file -# ================================== - -# The stylish-haskell tool is mainly configured by specifying steps. These steps -# are a list, so they have an order, and one specific step may appear more than -# once (if needed). Each file is processed by these steps in the given order. -steps: - # Convert some ASCII sequences to their Unicode equivalents. This is disabled - # by default. - # - unicode_syntax: - # # In order to make this work, we also need to insert the UnicodeSyntax - # # language pragma. If this flag is set to true, we insert it when it's - # # not already present. You may want to disable it if you configure - # # language extensions using some other method than pragmas. Default: - # # true. - # add_language_pragma: true - - # Import cleanup - - imports: - # There are different ways we can align names and lists. - # - # - global: Align the import names and import list throughout the entire - # file. - # - # - file: Like global, but don't add padding when there are no qualified - # imports in the file. - # - # - group: Only align the imports per group (a group is formed by adjacent - # import lines). - # - # - none: Do not perform any alignment. - # - # Default: global. - align: none - - # Folowing options affect only import list alignment. - # - # List align has following options: - # - # - after_alias: Import list is aligned with end of import including - # 'as' and 'hiding' keywords. - # - # > import qualified Data.List as List (concat, foldl, foldr, head, - # > init, last, length) - # - # - with_alias: Import list is aligned with start of alias or hiding. - # - # > import qualified Data.List as List (concat, foldl, foldr, head, - # > init, last, length) - # - # - new_line: Import list starts always on new line. - # - # > import qualified Data.List as List - # > (concat, foldl, foldr, head, init, last, length) - # - # Default: after alias - list_align: after_alias - - # Long list align style takes effect when import is too long. This is - # determined by 'columns' setting. - # - # - inline: This option will put as much specs on same line as possible. - # - # - new_line: Import list will start on new line. - # - # - new_line_multiline: Import list will start on new line when it's - # short enough to fit to single line. Otherwise it'll be multiline. - # - # - multiline: One line per import list entry. - # Type with contructor list acts like single import. - # - # > import qualified Data.Map as M - # > ( empty - # > , singleton - # > , ... - # > , delete - # > ) - # - # Default: inline - long_list_align: inline - - # List padding determines indentation of import list on lines after import. - # This option affects 'list_align' and 'long_list_align'. - list_padding: 2 - - # Separate lists option affects formating of import list for type - # or class. The only difference is single space between type and list - # of constructors, selectors and class functions. - # - # - true: There is single space between Foldable type and list of it's - # functions. - # - # > import Data.Foldable (Foldable (fold, foldl, foldMap)) - # - # - false: There is no space between Foldable type and list of it's - # functions. - # - # > import Data.Foldable (Foldable(fold, foldl, foldMap)) - # - # Default: true - separate_lists: true - - # Language pragmas - - language_pragmas: - # We can generate different styles of language pragma lists. - # - # - vertical: Vertical-spaced language pragmas, one per line. - # - # - compact: A more compact style. - # - # - compact_line: Similar to compact, but wrap each line with - # `{-#LANGUAGE #-}'. - # - # Default: vertical. - style: vertical - - # Align affects alignment of closing pragma brackets. - # - # - true: Brackets are aligned in same collumn. - # - # - false: Brackets are not aligned together. There is only one space - # between actual import and closing bracket. - # - # Default: true - align: false - - # stylish-haskell can detect redundancy of some language pragmas. If this - # is set to true, it will remove those redundant pragmas. Default: true. - remove_redundant: true - - # Align the types in record declarations - # - records: {} - - # Replace tabs by spaces. This is disabled by default. - # - tabs: - # # Number of spaces to use for each tab. Default: 8, as specified by the - # # Haskell report. - # spaces: 8 - - # Remove trailing whitespace - - trailing_whitespace: {} - -# A common setting is the number of columns (parts of) code will be wrapped -# to. Different steps take this into account. Default: 80. -columns: 110 - -# Sometimes, language extensions are specified in a cabal file or from the -# command line instead of using language pragmas in the file. stylish-haskell -# needs to be aware of these, so it can parse the file correctly. -# -# No language extensions are enabled by default. -language_extensions: - - TemplateHaskell diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ee4211dc..6a17e627 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,7 +47,7 @@ Make sure the project builds and that the tests pass! This will generally also b #### Dependencies -Include version bounds whenever adding a dependency to the library stanza of the cabal file. Note that libraries added to patch.cabal also need to be added to default.nix. +Include version bounds whenever adding a dependency to the library stanza of the cabal file. ### Documentation diff --git a/ChangeLog.md b/ChangeLog.md index 90e3d3fc..ac5b3006 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,9 +1,14 @@ # Revision history for patch -## 0.0.8.5 +## 0.0.9.0 * Strict `apply` for `PatchIntMap`, bringing it in line with the other `Map` types. * Support for GHC 9.14. +* Allow `these` 1.3 and `semialign` 1.4. +* Allow `containers` 0.8. +* Drop support for GHC older than 8.10. +* Drop the unused `semigroupoids` and `witherable` dependencies. +* Allow `hlint` up to 3.10 in the hlint test suite. ## 0.0.8.4 diff --git a/Setup.hs b/Setup.hs index 9a994af6..e8ef27db 100644 --- a/Setup.hs +++ b/Setup.hs @@ -1,2 +1,3 @@ import Distribution.Simple + main = defaultMain diff --git a/bench-cbits/checkCapability.c b/bench-cbits/checkCapability.c deleted file mode 100644 index 2ae967f4..00000000 --- a/bench-cbits/checkCapability.c +++ /dev/null @@ -1,208 +0,0 @@ -#include - -// The InCall structure represents either a single in-call from C to -// Haskell, or a worker thread. -typedef struct InCall_ { - StgTSO * tso; // the bound TSO (or NULL for a worker) - - StgTSO * suspended_tso; // the TSO is stashed here when we - // make a foreign call (NULL otherwise); - - Capability *suspended_cap; // The capability that the - // suspended_tso is on, because - // we can't read this from the TSO - // without owning a Capability in the - // first place. - - SchedulerStatus rstat; // return status - StgClosure ** ret; // return value - - struct Task_ *task; - - // When a Haskell thread makes a foreign call that re-enters - // Haskell, we end up with another Task associated with the - // current thread. We have to remember the whole stack of InCalls - // associated with the current Task so that we can correctly - // save & restore the InCall on entry to and exit from Haskell. - struct InCall_ *prev_stack; - - // Links InCalls onto suspended_ccalls, spare_incalls - struct InCall_ *prev; - struct InCall_ *next; -} InCall; - -typedef struct Task_ { -#if defined(THREADED_RTS) - OSThreadId id; // The OS Thread ID of this task - - Condition cond; // used for sleeping & waking up this task - Mutex lock; // lock for the condition variable - - // this flag tells the task whether it should wait on task->cond - // or just continue immediately. It's a workaround for the fact - // that signalling a condition variable doesn't do anything if the - // thread is already running, but we want it to be sticky. - HsBool wakeup; -#endif - - // This points to the Capability that the Task "belongs" to. If - // the Task owns a Capability, then task->cap points to it. If - // the task does not own a Capability, then either (a) if the task - // is a worker, then task->cap points to the Capability it belongs - // to, or (b) it is returning from a foreign call, then task->cap - // points to the Capability with the returning_worker queue that this - // this Task is on. - // - // When a task goes to sleep, it may be migrated to a different - // Capability. Hence, we always check task->cap on wakeup. To - // syncrhonise between the migrater and the migratee, task->lock - // must be held when modifying task->cap. - struct Capability_ *cap; - - // The current top-of-stack InCall - struct InCall_ *incall; - - uint32_t n_spare_incalls; - struct InCall_ *spare_incalls; - - HsBool worker; // == rtsTrue if this is a worker Task - HsBool stopped; // this task has stopped or exited Haskell - - // So that we can detect when a finalizer illegally calls back into Haskell - HsBool running_finalizers; - - // Links tasks on the returning_tasks queue of a Capability, and - // on spare_workers. - struct Task_ *next; - - // Links tasks on the all_tasks list; need ACQUIRE_LOCK(&all_tasks_mutex) - struct Task_ *all_next; - struct Task_ *all_prev; - -} Task; - -struct Capability_ { - // State required by the STG virtual machine when running Haskell - // code. During STG execution, the BaseReg register always points - // to the StgRegTable of the current Capability (&cap->r). - StgFunTable f; - StgRegTable r; - - uint32_t no; // capability number. - - // The Task currently holding this Capability. This task has - // exclusive access to the contents of this Capability (apart from - // returning_tasks_hd/returning_tasks_tl). - // Locks required: cap->lock. - Task *running_task; - - // true if this Capability is running Haskell code, used for - // catching unsafe call-ins. - HsBool in_haskell; - - // Has there been any activity on this Capability since the last GC? - uint32_t idle; - - HsBool disabled; - - // The run queue. The Task owning this Capability has exclusive - // access to its run queue, so can wake up threads without - // taking a lock, and the common path through the scheduler is - // also lock-free. - StgTSO *run_queue_hd; - StgTSO *run_queue_tl; - - // Tasks currently making safe foreign calls. Doubly-linked. - // When returning, a task first acquires the Capability before - // removing itself from this list, so that the GC can find all - // the suspended TSOs easily. Hence, when migrating a Task from - // the returning_tasks list, we must also migrate its entry from - // this list. - InCall *suspended_ccalls; - - // One mutable list per generation, so we don't need to take any - // locks when updating an old-generation thunk. This also lets us - // keep track of which closures this CPU has been mutating, so we - // can traverse them using the right thread during GC and avoid - // unnecessarily moving the data from one cache to another. - bdescr **mut_lists; - bdescr **saved_mut_lists; // tmp use during GC - - // block for allocating pinned objects into - bdescr *pinned_object_block; - // full pinned object blocks allocated since the last GC - bdescr *pinned_object_blocks; - - // per-capability weak pointer list associated with nursery (older - // lists stored in generation object) - StgWeak *weak_ptr_list_hd; - StgWeak *weak_ptr_list_tl; - - // Context switch flag. When non-zero, this means: stop running - // Haskell code, and switch threads. - int context_switch; - - // Interrupt flag. Like the context_switch flag, this also - // indicates that we should stop running Haskell code, but we do - // *not* switch threads. This is used to stop a Capability in - // order to do GC, for example. - // - // The interrupt flag is always reset before we start running - // Haskell code, unlike the context_switch flag which is only - // reset after we have executed the context switch. - int interrupt; - - // Total words allocated by this cap since rts start - // See [Note allocation accounting] in Storage.c - W_ total_allocated; - -#if defined(THREADED_RTS) - // Worker Tasks waiting in the wings. Singly-linked. - Task *spare_workers; - uint32_t n_spare_workers; // count of above - - // This lock protects: - // running_task - // returning_tasks_{hd,tl} - // wakeup_queue - // inbox - Mutex lock; - - // Tasks waiting to return from a foreign call, or waiting to make - // a new call-in using this Capability (NULL if empty). - // NB. this field needs to be modified by tasks other than the - // running_task, so it requires cap->lock to modify. A task can - // check whether it is NULL without taking the lock, however. - Task *returning_tasks_hd; // Singly-linked, with head/tail - Task *returning_tasks_tl; - - // Messages, or END_TSO_QUEUE. - // Locks required: cap->lock - Message *inbox; - - SparkPool *sparks; - - // Stats on spark creation/conversion - SparkCounters spark_stats; -#if !defined(mingw32_HOST_OS) - // IO manager for this cap - int io_manager_control_wr_fd; -#endif -#endif - - // Per-capability STM-related data - StgTVarWatchQueue *free_tvar_watch_queues; - StgTRecChunk *free_trec_chunks; - StgTRecHeader *free_trec_headers; - uint32_t transaction_tokens; -} // typedef Capability is defined in RtsAPI.h - // We never want a Capability to overlap a cache line with anything - // else, so round it up to a cache line size: -#ifndef mingw32_HOST_OS - ATTRIBUTE_ALIGNED(64) -#endif - ; - -HsBool myCapabilityHasOtherRunnableThreads() { - return rts_unsafeGetMyCapability()->run_queue_hd == END_TSO_QUEUE ? HS_BOOL_FALSE : HS_BOOL_TRUE; -} diff --git a/cabal.project b/cabal.project index 6210c002..d0c55f06 100644 --- a/cabal.project +++ b/cabal.project @@ -2,3 +2,5 @@ packages: . if arch(javascript) extra-packages: ghci + -- ghci for GHC 9.14 needs containers 0.8, which dependent-map 0.4.0.1 excludes + allow-newer: dependent-map:containers diff --git a/default.nix b/default.nix new file mode 100644 index 00000000..c679387d --- /dev/null +++ b/default.nix @@ -0,0 +1,11 @@ +{ system ? builtins.currentSystem +, inputs ? import ./inputs.nix { inherit system; } +}: + +let nix-haskell = import inputs.nix-haskell { inherit system inputs; }; + project = nix-haskell (import ./project.nix); + +in { + haskell-nix = project.haskell-nix.project; + nixpkgs = project.nixpkgs.project; +} diff --git a/nix/deps/nix-haskell-ci/default.nix b/deps/nix-haskell/default.nix similarity index 100% rename from nix/deps/nix-haskell-ci/default.nix rename to deps/nix-haskell/default.nix diff --git a/deps/nix-haskell/flake.lock b/deps/nix-haskell/flake.lock new file mode 100644 index 00000000..2082fb68 --- /dev/null +++ b/deps/nix-haskell/flake.lock @@ -0,0 +1,987 @@ +{ + "nodes": { + "HTTP": { + "flake": false, + "locked": { + "lastModified": 1451647621, + "narHash": "sha256-oHIyw3x0iKBexEo49YeUDV1k74ZtyYKGR2gNJXXRxts=", + "owner": "phadej", + "repo": "HTTP", + "rev": "9bc0996d412fef1787449d841277ef663ad9a915", + "type": "github" + }, + "original": { + "narHash": "sha256-oHIyw3x0iKBexEo49YeUDV1k74ZtyYKGR2gNJXXRxts=", + "owner": "phadej", + "repo": "HTTP", + "rev": "9bc0996d412fef1787449d841277ef663ad9a915", + "type": "github" + } + }, + "cabal-34": { + "flake": false, + "locked": { + "lastModified": 1645834128, + "narHash": "sha256-wG3d+dOt14z8+ydz4SL7pwGfe7SiimxcD/LOuPCV6xM=", + "owner": "haskell", + "repo": "cabal", + "rev": "5ff598c67f53f7c4f48e31d722ba37172230c462", + "type": "github" + }, + "original": { + "narHash": "sha256-wG3d+dOt14z8+ydz4SL7pwGfe7SiimxcD/LOuPCV6xM=", + "owner": "haskell", + "repo": "cabal", + "rev": "5ff598c67f53f7c4f48e31d722ba37172230c462", + "type": "github" + } + }, + "cabal-36": { + "flake": false, + "locked": { + "lastModified": 1669081697, + "narHash": "sha256-I5or+V7LZvMxfbYgZATU4awzkicBwwok4mVoje+sGmU=", + "owner": "haskell", + "repo": "cabal", + "rev": "8fd619e33d34924a94e691c5fea2c42f0fc7f144", + "type": "github" + }, + "original": { + "narHash": "sha256-I5or+V7LZvMxfbYgZATU4awzkicBwwok4mVoje+sGmU=", + "owner": "haskell", + "repo": "cabal", + "rev": "8fd619e33d34924a94e691c5fea2c42f0fc7f144", + "type": "github" + } + }, + "cabal-doctest": { + "flake": false, + "locked": { + "lastModified": 1787831028, + "narHash": "sha256-YUSquN8tlV59hWoArmP5wxHxK8lIjcmZofxNQTMC4IQ=", + "owner": "stable-haskell", + "repo": "cabal-doctest", + "rev": "641cda5a4590f2384568a9598713f3039b99258d", + "type": "github" + }, + "original": { + "narHash": "sha256-YUSquN8tlV59hWoArmP5wxHxK8lIjcmZofxNQTMC4IQ=", + "owner": "stable-haskell", + "repo": "cabal-doctest", + "rev": "641cda5a4590f2384568a9598713f3039b99258d", + "type": "github" + } + }, + "cardano-shell": { + "flake": false, + "locked": { + "lastModified": 1608537748, + "narHash": "sha256-PulY1GfiMgKVnBci3ex4ptk2UNYMXqGjJOxcPy2KYT4=", + "owner": "input-output-hk", + "repo": "cardano-shell", + "rev": "9392c75087cb9a3d453998f4230930dea3a95725", + "type": "github" + }, + "original": { + "narHash": "sha256-PulY1GfiMgKVnBci3ex4ptk2UNYMXqGjJOxcPy2KYT4=", + "owner": "input-output-hk", + "repo": "cardano-shell", + "rev": "9392c75087cb9a3d453998f4230930dea3a95725", + "type": "github" + } + }, + "flake-compat": { + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1672831974, + "narHash": "sha256-z9k3MfslLjWQfnjBtEtJZdq3H7kyi2kQtUThfTgdRk0=", + "owner": "input-output-hk", + "repo": "flake-compat", + "rev": "45f2638735f8cdc40fe302742b79f248d23eb368", + "type": "github" + }, + "original": { + "narHash": "sha256-z9k3MfslLjWQfnjBtEtJZdq3H7kyi2kQtUThfTgdRk0=", + "owner": "input-output-hk", + "repo": "flake-compat", + "rev": "45f2638735f8cdc40fe302742b79f248d23eb368", + "type": "github" + } + }, + "hackage": { + "flake": false, + "locked": { + "lastModified": 1794026965, + "narHash": "sha256-aAn6YyEMPmNlQTY3XM2viwZP5+jSih2PXsJNl5I9Tw8=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "6262c828b6539dadc7a567e65be26bf3c45fda6c", + "type": "github" + }, + "original": { + "narHash": "sha256-aAn6YyEMPmNlQTY3XM2viwZP5+jSih2PXsJNl5I9Tw8=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "6262c828b6539dadc7a567e65be26bf3c45fda6c", + "type": "github" + } + }, + "hackage-for-stackage": { + "flake": false, + "locked": { + "lastModified": 1794026940, + "narHash": "sha256-dmR6z5cDs9Jjnz4zNAdTdML5cHxeUJrFdozvsAd66UQ=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "30337ea718070b928e1c51454a85c51e035b3cad", + "type": "github" + }, + "original": { + "narHash": "sha256-dmR6z5cDs9Jjnz4zNAdTdML5cHxeUJrFdozvsAd66UQ=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "30337ea718070b928e1c51454a85c51e035b3cad", + "type": "github" + } + }, + "hackage-internal": { + "flake": false, + "locked": { + "lastModified": 1750307553, + "narHash": "sha256-iiafNoeLHwlSLQTyvy8nPe2t6g5AV4PPcpMeH/2/DLs=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "f7867baa8817fab296528f4a4ec39d1c7c4da4f3", + "type": "github" + }, + "original": { + "narHash": "sha256-iiafNoeLHwlSLQTyvy8nPe2t6g5AV4PPcpMeH/2/DLs=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "f7867baa8817fab296528f4a4ec39d1c7c4da4f3", + "type": "github" + } + }, + "hackage-overlay-repo-tool": { + "flake": false, + "locked": { + "lastModified": 1671663228, + "narHash": "sha256-GKeke8FT9w2u6J9aI4eN3mOV0BURHiytQAEir4/4M1Q=", + "owner": "bgamari", + "repo": "hackage-overlay-repo-tool", + "rev": "f60aa0d497961745a503ddea2adb0facb58376e8", + "type": "github" + }, + "original": { + "narHash": "sha256-GKeke8FT9w2u6J9aI4eN3mOV0BURHiytQAEir4/4M1Q=", + "owner": "bgamari", + "repo": "hackage-overlay-repo-tool", + "rev": "f60aa0d497961745a503ddea2adb0facb58376e8", + "type": "github" + } + }, + "haskell-nix": { + "inputs": { + "HTTP": [ + "HTTP" + ], + "cabal-34": [ + "cabal-34" + ], + "cabal-36": [ + "cabal-36" + ], + "cabal-doctest": [ + "cabal-doctest" + ], + "cardano-shell": [ + "cardano-shell" + ], + "flake-compat": [ + "flake-compat_2" + ], + "hackage": [ + "hackage" + ], + "hackage-for-stackage": [ + "hackage-for-stackage" + ], + "hackage-internal": [ + "hackage-internal" + ], + "hackage-overlay-repo-tool": [ + "hackage-overlay-repo-tool" + ], + "head-hackage": [ + "head-hackage" + ], + "hls": [ + "hls" + ], + "hls-1.10": [ + "hls-1_10" + ], + "hls-2.0": [ + "hls-2_0" + ], + "hls-2.10": [ + "hls-2_10" + ], + "hls-2.11": [ + "hls-2_11" + ], + "hls-2.12": [ + "hls-2_12" + ], + "hls-2.2": [ + "hls-2_2" + ], + "hls-2.3": [ + "hls-2_3" + ], + "hls-2.4": [ + "hls-2_4" + ], + "hls-2.5": [ + "hls-2_5" + ], + "hls-2.6": [ + "hls-2_6" + ], + "hls-2.7": [ + "hls-2_7" + ], + "hls-2.8": [ + "hls-2_8" + ], + "hls-2.9": [ + "hls-2_9" + ], + "hpc-coveralls": [ + "hpc-coveralls" + ], + "hyper-linux": [ + "hyper-linux" + ], + "iserv-proxy": [ + "iserv-proxy" + ], + "nixpkgs": [ + "nixpkgs-unstable" + ], + "nixpkgs-2305": [ + "nixpkgs-2305" + ], + "nixpkgs-2311": [ + "nixpkgs-2311" + ], + "nixpkgs-2405": [ + "nixpkgs-2405" + ], + "nixpkgs-2411": [ + "nixpkgs-2411" + ], + "nixpkgs-2505": [ + "nixpkgs-2505" + ], + "nixpkgs-2511": [ + "nixpkgs-2511" + ], + "nixpkgs-2605": [ + "nixpkgs-2605" + ], + "nixpkgs-unstable": [ + "nixpkgs-unstable" + ], + "old-ghc-nix": [ + "old-ghc-nix" + ], + "stackage": [ + "stackage" + ] + }, + "locked": { + "allRefs": true, + "dir": "pins/haskell-nix", + "lastModified": 1794571666, + "narHash": "sha256-bisRbEDfFaS+rbt06+bMTn6U8277+fDJGLUZoF0GDKM=", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + }, + "original": { + "allRefs": true, + "dir": "pins/haskell-nix", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + } + }, + "head-hackage": { + "flake": false, + "locked": { + "host": "gitlab.haskell.org", + "lastModified": 1780387533, + "narHash": "sha256-oifEa/JYg8ZLUtkbM8HVzKmqCcT9QxaDmG0ex2qT0Ng=", + "owner": "ghc", + "repo": "head.hackage", + "rev": "a50bec6c7722f774415bc0f0a0e64f6e2b8989b7", + "type": "gitlab" + }, + "original": { + "host": "gitlab.haskell.org", + "narHash": "sha256-oifEa/JYg8ZLUtkbM8HVzKmqCcT9QxaDmG0ex2qT0Ng=", + "owner": "ghc", + "repo": "head.hackage", + "rev": "a50bec6c7722f774415bc0f0a0e64f6e2b8989b7", + "type": "gitlab" + } + }, + "hls": { + "flake": false, + "locked": { + "lastModified": 1741604408, + "narHash": "sha256-tuq3+Ip70yu89GswZ7DSINBpwRprnWnl6xDYnS4GOsc=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "682d6894c94087da5e566771f25311c47e145359", + "type": "github" + }, + "original": { + "narHash": "sha256-tuq3+Ip70yu89GswZ7DSINBpwRprnWnl6xDYnS4GOsc=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "682d6894c94087da5e566771f25311c47e145359", + "type": "github" + } + }, + "hls-1_10": { + "flake": false, + "locked": { + "lastModified": 1680000865, + "narHash": "sha256-rc7iiUAcrHxwRM/s0ErEsSPxOR3u8t7DvFeWlMycWgo=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "b08691db779f7a35ff322b71e72a12f6e3376fd9", + "type": "github" + }, + "original": { + "narHash": "sha256-rc7iiUAcrHxwRM/s0ErEsSPxOR3u8t7DvFeWlMycWgo=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "b08691db779f7a35ff322b71e72a12f6e3376fd9", + "type": "github" + } + }, + "hls-2_0": { + "flake": false, + "locked": { + "lastModified": 1687698105, + "narHash": "sha256-OHXlgRzs/kuJH8q7Sxh507H+0Rb8b7VOiPAjcY9sM1k=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "783905f211ac63edf982dd1889c671653327e441", + "type": "github" + }, + "original": { + "narHash": "sha256-OHXlgRzs/kuJH8q7Sxh507H+0Rb8b7VOiPAjcY9sM1k=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "783905f211ac63edf982dd1889c671653327e441", + "type": "github" + } + }, + "hls-2_10": { + "flake": false, + "locked": { + "lastModified": 1743069404, + "narHash": "sha256-q4kDFyJDDeoGqfEtrZRx4iqMVEC2MOzCToWsFY+TOzY=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "2318c61db3a01e03700bd4b05665662929b7fe8b", + "type": "github" + }, + "original": { + "narHash": "sha256-q4kDFyJDDeoGqfEtrZRx4iqMVEC2MOzCToWsFY+TOzY=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "2318c61db3a01e03700bd4b05665662929b7fe8b", + "type": "github" + } + }, + "hls-2_11": { + "flake": false, + "locked": { + "lastModified": 1747306193, + "narHash": "sha256-/MmtpF8+FyQlwfKHqHK05BdsxC9LHV70d/FiMM7pzBM=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "46ef4523ea4949f47f6d2752476239f1c6d806fe", + "type": "github" + }, + "original": { + "narHash": "sha256-/MmtpF8+FyQlwfKHqHK05BdsxC9LHV70d/FiMM7pzBM=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "46ef4523ea4949f47f6d2752476239f1c6d806fe", + "type": "github" + } + }, + "hls-2_12": { + "flake": false, + "locked": { + "lastModified": 1758709460, + "narHash": "sha256-xkI8MIIVEVARskfWbGAgP5sHG/lyeKnkm0LIOJ19X5w=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "7d983de4fa7ff54369f6dd31444bdb9869aec83e", + "type": "github" + }, + "original": { + "narHash": "sha256-xkI8MIIVEVARskfWbGAgP5sHG/lyeKnkm0LIOJ19X5w=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "7d983de4fa7ff54369f6dd31444bdb9869aec83e", + "type": "github" + } + }, + "hls-2_2": { + "flake": false, + "locked": { + "lastModified": 1693064058, + "narHash": "sha256-8DGIyz5GjuCFmohY6Fa79hHA/p1iIqubfJUTGQElbNk=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "b30f4b6cf5822f3112c35d14a0cba51f3fe23b85", + "type": "github" + }, + "original": { + "narHash": "sha256-8DGIyz5GjuCFmohY6Fa79hHA/p1iIqubfJUTGQElbNk=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "b30f4b6cf5822f3112c35d14a0cba51f3fe23b85", + "type": "github" + } + }, + "hls-2_3": { + "flake": false, + "locked": { + "lastModified": 1695910642, + "narHash": "sha256-tR58doOs3DncFehHwCLczJgntyG/zlsSd7DgDgMPOkI=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "458ccdb55c9ea22cd5d13ec3051aaefb295321be", + "type": "github" + }, + "original": { + "narHash": "sha256-tR58doOs3DncFehHwCLczJgntyG/zlsSd7DgDgMPOkI=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "458ccdb55c9ea22cd5d13ec3051aaefb295321be", + "type": "github" + } + }, + "hls-2_4": { + "flake": false, + "locked": { + "lastModified": 1699862708, + "narHash": "sha256-YHXSkdz53zd0fYGIYOgLt6HrA0eaRJi9mXVqDgmvrjk=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "54507ef7e85fa8e9d0eb9a669832a3287ffccd57", + "type": "github" + }, + "original": { + "narHash": "sha256-YHXSkdz53zd0fYGIYOgLt6HrA0eaRJi9mXVqDgmvrjk=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "54507ef7e85fa8e9d0eb9a669832a3287ffccd57", + "type": "github" + } + }, + "hls-2_5": { + "flake": false, + "locked": { + "lastModified": 1701080174, + "narHash": "sha256-fyiR9TaHGJIIR0UmcCb73Xv9TJq3ht2ioxQ2mT7kVdc=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "27f8c3d3892e38edaef5bea3870161815c4d014c", + "type": "github" + }, + "original": { + "narHash": "sha256-fyiR9TaHGJIIR0UmcCb73Xv9TJq3ht2ioxQ2mT7kVdc=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "27f8c3d3892e38edaef5bea3870161815c4d014c", + "type": "github" + } + }, + "hls-2_6": { + "flake": false, + "locked": { + "lastModified": 1705325287, + "narHash": "sha256-+P87oLdlPyMw8Mgoul7HMWdEvWP/fNlo8jyNtwME8E8=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "6e0b342fa0327e628610f2711f8c3e4eaaa08b1e", + "type": "github" + }, + "original": { + "narHash": "sha256-+P87oLdlPyMw8Mgoul7HMWdEvWP/fNlo8jyNtwME8E8=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "6e0b342fa0327e628610f2711f8c3e4eaaa08b1e", + "type": "github" + } + }, + "hls-2_7": { + "flake": false, + "locked": { + "lastModified": 1708965829, + "narHash": "sha256-LfJ+TBcBFq/XKoiNI7pc4VoHg4WmuzsFxYJ3Fu+Jf+M=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "50322b0a4aefb27adc5ec42f5055aaa8f8e38001", + "type": "github" + }, + "original": { + "narHash": "sha256-LfJ+TBcBFq/XKoiNI7pc4VoHg4WmuzsFxYJ3Fu+Jf+M=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "50322b0a4aefb27adc5ec42f5055aaa8f8e38001", + "type": "github" + } + }, + "hls-2_8": { + "flake": false, + "locked": { + "lastModified": 1715153580, + "narHash": "sha256-Vi/iUt2pWyUJlo9VrYgTcbRviWE0cFO6rmGi9rmALw0=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "dd1be1beb16700de59e0d6801957290bcf956a0a", + "type": "github" + }, + "original": { + "narHash": "sha256-Vi/iUt2pWyUJlo9VrYgTcbRviWE0cFO6rmGi9rmALw0=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "dd1be1beb16700de59e0d6801957290bcf956a0a", + "type": "github" + } + }, + "hls-2_9": { + "flake": false, + "locked": { + "lastModified": 1719993701, + "narHash": "sha256-wy348++MiMm/xwtI9M3vVpqj2qfGgnDcZIGXw8sF1sA=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "90319a7e62ab93ab65a95f8f2bcf537e34dae76a", + "type": "github" + }, + "original": { + "narHash": "sha256-wy348++MiMm/xwtI9M3vVpqj2qfGgnDcZIGXw8sF1sA=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "90319a7e62ab93ab65a95f8f2bcf537e34dae76a", + "type": "github" + } + }, + "hpc-coveralls": { + "flake": false, + "locked": { + "lastModified": 1607498076, + "narHash": "sha256-8uqsEtivphgZWYeUo5RDUhp6bO9j2vaaProQxHBltQk=", + "owner": "sevanspowell", + "repo": "hpc-coveralls", + "rev": "14df0f7d229f4cd2e79f8eabb1a740097fdfa430", + "type": "github" + }, + "original": { + "narHash": "sha256-8uqsEtivphgZWYeUo5RDUhp6bO9j2vaaProQxHBltQk=", + "owner": "sevanspowell", + "repo": "hpc-coveralls", + "rev": "14df0f7d229f4cd2e79f8eabb1a740097fdfa430", + "type": "github" + } + }, + "hyper-linux": { + "inputs": { + "nixpkgs": [ + "nixpkgs-unstable" + ] + }, + "locked": { + "lastModified": 1773548649, + "narHash": "sha256-041m8HOyieDscFuzbgC764K+LTi4pSJH5+HwTSveJT8=", + "owner": "zw3rk", + "repo": "hyper-linux", + "rev": "41cea39c8d8243d729991d0c26515f6bfe7be7fb", + "type": "github" + }, + "original": { + "narHash": "sha256-041m8HOyieDscFuzbgC764K+LTi4pSJH5+HwTSveJT8=", + "owner": "zw3rk", + "repo": "hyper-linux", + "rev": "41cea39c8d8243d729991d0c26515f6bfe7be7fb", + "type": "github" + } + }, + "iserv-proxy": { + "flake": false, + "locked": { + "lastModified": 1793394322, + "narHash": "sha256-BXCMjVXEs40oVlNicxD+nrVSvf9R0KT+dLl0mOdGm0I=", + "owner": "stable-haskell", + "repo": "iserv-proxy", + "rev": "5c483b26074f2b9b8056ce71e7a3c44c02c4d7c0", + "type": "github" + }, + "original": { + "narHash": "sha256-BXCMjVXEs40oVlNicxD+nrVSvf9R0KT+dLl0mOdGm0I=", + "owner": "stable-haskell", + "repo": "iserv-proxy", + "rev": "5c483b26074f2b9b8056ce71e7a3c44c02c4d7c0", + "type": "github" + } + }, + "nixpkgs": { + "inputs": { + "upstream": [ + "upstream" + ] + }, + "locked": { + "allRefs": true, + "dir": "pins/nixpkgs", + "lastModified": 1794571666, + "narHash": "sha256-bisRbEDfFaS+rbt06+bMTn6U8277+fDJGLUZoF0GDKM=", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + }, + "original": { + "allRefs": true, + "dir": "pins/nixpkgs", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + } + }, + "nixpkgs-2305": { + "locked": { + "lastModified": 1705033721, + "narHash": "sha256-K5eJHmL1/kev6WuqyqqbS1cdNnSidIZ3jeqJ7GbrYnQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a1982c92d8980a0114372973cbdfe0a307f1bdea", + "type": "github" + }, + "original": { + "narHash": "sha256-K5eJHmL1/kev6WuqyqqbS1cdNnSidIZ3jeqJ7GbrYnQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a1982c92d8980a0114372973cbdfe0a307f1bdea", + "type": "github" + } + }, + "nixpkgs-2311": { + "locked": { + "lastModified": 1719957072, + "narHash": "sha256-gvFhEf5nszouwLAkT9nWsDzocUTqLWHuL++dvNjMp9I=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7144d6241f02d171d25fba3edeaf15e0f2592105", + "type": "github" + }, + "original": { + "narHash": "sha256-gvFhEf5nszouwLAkT9nWsDzocUTqLWHuL++dvNjMp9I=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7144d6241f02d171d25fba3edeaf15e0f2592105", + "type": "github" + } + }, + "nixpkgs-2405": { + "locked": { + "lastModified": 1735564410, + "narHash": "sha256-HB/FA0+1gpSs8+/boEavrGJH+Eq08/R2wWNph1sM1Dg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1e7a8f391f1a490460760065fa0630b5520f9cf8", + "type": "github" + }, + "original": { + "narHash": "sha256-HB/FA0+1gpSs8+/boEavrGJH+Eq08/R2wWNph1sM1Dg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1e7a8f391f1a490460760065fa0630b5520f9cf8", + "type": "github" + } + }, + "nixpkgs-2411": { + "locked": { + "lastModified": 1751290243, + "narHash": "sha256-kNf+obkpJZWar7HZymXZbW+Rlk3HTEIMlpc6FCNz0Ds=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5ab036a8d97cb9476fbe81b09076e6e91d15e1b6", + "type": "github" + }, + "original": { + "narHash": "sha256-kNf+obkpJZWar7HZymXZbW+Rlk3HTEIMlpc6FCNz0Ds=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5ab036a8d97cb9476fbe81b09076e6e91d15e1b6", + "type": "github" + } + }, + "nixpkgs-2505": { + "locked": { + "lastModified": 1768649915, + "narHash": "sha256-jc21hKogFnxU7KXSVTRmxC7u5D4RHwm9BAvDf5/Z1Uo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3e3f3c7f9977dc123c23ee21e8085ed63daf8c37", + "type": "github" + }, + "original": { + "narHash": "sha256-jc21hKogFnxU7KXSVTRmxC7u5D4RHwm9BAvDf5/Z1Uo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3e3f3c7f9977dc123c23ee21e8085ed63daf8c37", + "type": "github" + } + }, + "nixpkgs-2511": { + "locked": { + "lastModified": 1782904953, + "narHash": "sha256-ESJ4VgytmAt+98YLM8466luln4HyEZ9Q36b9+Bb4P5w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0921fdb3e13e40fe25fbc52b89661a9d6d32ac68", + "type": "github" + }, + "original": { + "narHash": "sha256-ESJ4VgytmAt+98YLM8466luln4HyEZ9Q36b9+Bb4P5w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0921fdb3e13e40fe25fbc52b89661a9d6d32ac68", + "type": "github" + } + }, + "nixpkgs-2605": { + "locked": { + "lastModified": 1793147889, + "narHash": "sha256-+//qXhkXCKTFoVCHAYhoEP1ZnPSx/b4IHdLI1ZMz3UU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "36173dbc6ff2b383c4d03b002fd1ea58e2e4dbcd", + "type": "github" + }, + "original": { + "narHash": "sha256-+//qXhkXCKTFoVCHAYhoEP1ZnPSx/b4IHdLI1ZMz3UU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "36173dbc6ff2b383c4d03b002fd1ea58e2e4dbcd", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1793494649, + "narHash": "sha256-Thn0OE71NF80ZfOMGCgJvKtbCcnnz0fToT/qsvb/Gtc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d357a2b54f0b6dc4aeb4e993190a52cf151b6f24", + "type": "github" + }, + "original": { + "narHash": "sha256-Thn0OE71NF80ZfOMGCgJvKtbCcnnz0fToT/qsvb/Gtc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d357a2b54f0b6dc4aeb4e993190a52cf151b6f24", + "type": "github" + } + }, + "old-ghc-nix": { + "flake": false, + "locked": { + "lastModified": 1631092763, + "narHash": "sha256-sIKgO+z7tj4lw3u6oBZxqIhDrzSkvpHtv0Kki+lh9Fg=", + "owner": "angerman", + "repo": "old-ghc-nix", + "rev": "af48a7a7353e418119b6dfe3cd1463a657f342b8", + "type": "github" + }, + "original": { + "narHash": "sha256-sIKgO+z7tj4lw3u6oBZxqIhDrzSkvpHtv0Kki+lh9Fg=", + "owner": "angerman", + "repo": "old-ghc-nix", + "rev": "af48a7a7353e418119b6dfe3cd1463a657f342b8", + "type": "github" + } + }, + "root": { + "inputs": { + "HTTP": "HTTP", + "cabal-34": "cabal-34", + "cabal-36": "cabal-36", + "cabal-doctest": "cabal-doctest", + "cardano-shell": "cardano-shell", + "flake-compat": "flake-compat", + "flake-compat_2": "flake-compat_2", + "hackage": "hackage", + "hackage-for-stackage": "hackage-for-stackage", + "hackage-internal": "hackage-internal", + "hackage-overlay-repo-tool": "hackage-overlay-repo-tool", + "haskell-nix": "haskell-nix", + "head-hackage": "head-hackage", + "hls": "hls", + "hls-1_10": "hls-1_10", + "hls-2_0": "hls-2_0", + "hls-2_10": "hls-2_10", + "hls-2_11": "hls-2_11", + "hls-2_12": "hls-2_12", + "hls-2_2": "hls-2_2", + "hls-2_3": "hls-2_3", + "hls-2_4": "hls-2_4", + "hls-2_5": "hls-2_5", + "hls-2_6": "hls-2_6", + "hls-2_7": "hls-2_7", + "hls-2_8": "hls-2_8", + "hls-2_9": "hls-2_9", + "hpc-coveralls": "hpc-coveralls", + "hyper-linux": "hyper-linux", + "iserv-proxy": "iserv-proxy", + "nixpkgs": "nixpkgs", + "nixpkgs-2305": "nixpkgs-2305", + "nixpkgs-2311": "nixpkgs-2311", + "nixpkgs-2405": "nixpkgs-2405", + "nixpkgs-2411": "nixpkgs-2411", + "nixpkgs-2505": "nixpkgs-2505", + "nixpkgs-2511": "nixpkgs-2511", + "nixpkgs-2605": "nixpkgs-2605", + "nixpkgs-unstable": "nixpkgs-unstable", + "old-ghc-nix": "old-ghc-nix", + "sandstone": "sandstone", + "stackage": "stackage", + "upstream": "upstream", + "upstream_2": "upstream_2" + } + }, + "sandstone": { + "flake": false, + "locked": { + "allRefs": true, + "dir": "pins/sandstone", + "lastModified": 1794571666, + "narHash": "sha256-bisRbEDfFaS+rbt06+bMTn6U8277+fDJGLUZoF0GDKM=", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + }, + "original": { + "allRefs": true, + "dir": "pins/sandstone", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + } + }, + "stackage": { + "flake": false, + "locked": { + "lastModified": 1794024259, + "narHash": "sha256-1XjknkUH8ENHQaoWSO+M3US7/vJsEYjMgBVdci9DBmI=", + "owner": "input-output-hk", + "repo": "stackage.nix", + "rev": "2b2df46b0dbe0f415c3c69a42f922f9f2a473e91", + "type": "github" + }, + "original": { + "narHash": "sha256-1XjknkUH8ENHQaoWSO+M3US7/vJsEYjMgBVdci9DBmI=", + "owner": "input-output-hk", + "repo": "stackage.nix", + "rev": "2b2df46b0dbe0f415c3c69a42f922f9f2a473e91", + "type": "github" + } + }, + "upstream": { + "locked": { + "lastModified": 1794165970, + "narHash": "sha256-XuAV2cUwaod3Bt4XFVqiXz3v1w2ex16W6Sv4S7EWres=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ac588ef1c914865dad517b337ea0eb9694a4021c", + "type": "github" + }, + "original": { + "narHash": "sha256-XuAV2cUwaod3Bt4XFVqiXz3v1w2ex16W6Sv4S7EWres=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ac588ef1c914865dad517b337ea0eb9694a4021c", + "type": "github" + } + }, + "upstream_2": { + "inputs": { + "flake-compat": [ + "flake-compat" + ], + "haskell-nix": [ + "haskell-nix" + ], + "nixpkgs": [ + "nixpkgs" + ], + "sandstone": [ + "sandstone" + ] + }, + "locked": { + "allRefs": true, + "lastModified": 1794571666, + "narHash": "sha256-bisRbEDfFaS+rbt06+bMTn6U8277+fDJGLUZoF0GDKM=", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + }, + "original": { + "allRefs": true, + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/deps/nix-haskell/flake.nix b/deps/nix-haskell/flake.nix new file mode 100644 index 00000000..50c7e0d7 --- /dev/null +++ b/deps/nix-haskell/flake.nix @@ -0,0 +1,401 @@ +# DO NOT HAND-EDIT THIS FILE +{ + inputs = { + "upstream_2" = { + allRefs = true; + rev = "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e"; + submodules = true; + type = "git"; + url = "https://github.com/reflex-frp/nix-haskell.git"; + inputs = { + "flake-compat" = { follows = "flake-compat"; }; + "haskell-nix" = { follows = "haskell-nix"; }; + "nixpkgs" = { follows = "nixpkgs"; }; + "sandstone" = { follows = "sandstone"; }; + }; + }; + "HTTP" = { + flake = false; + narHash = "sha256-oHIyw3x0iKBexEo49YeUDV1k74ZtyYKGR2gNJXXRxts="; + owner = "phadej"; + repo = "HTTP"; + rev = "9bc0996d412fef1787449d841277ef663ad9a915"; + type = "github"; + }; + "cabal-34" = { + flake = false; + narHash = "sha256-wG3d+dOt14z8+ydz4SL7pwGfe7SiimxcD/LOuPCV6xM="; + owner = "haskell"; + repo = "cabal"; + rev = "5ff598c67f53f7c4f48e31d722ba37172230c462"; + type = "github"; + }; + "cabal-36" = { + flake = false; + narHash = "sha256-I5or+V7LZvMxfbYgZATU4awzkicBwwok4mVoje+sGmU="; + owner = "haskell"; + repo = "cabal"; + rev = "8fd619e33d34924a94e691c5fea2c42f0fc7f144"; + type = "github"; + }; + "cabal-doctest" = { + flake = false; + narHash = "sha256-YUSquN8tlV59hWoArmP5wxHxK8lIjcmZofxNQTMC4IQ="; + owner = "stable-haskell"; + repo = "cabal-doctest"; + rev = "641cda5a4590f2384568a9598713f3039b99258d"; + type = "github"; + }; + "cardano-shell" = { + flake = false; + narHash = "sha256-PulY1GfiMgKVnBci3ex4ptk2UNYMXqGjJOxcPy2KYT4="; + owner = "input-output-hk"; + repo = "cardano-shell"; + rev = "9392c75087cb9a3d453998f4230930dea3a95725"; + type = "github"; + }; + "flake-compat" = { + narHash = "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns="; + owner = "NixOS"; + repo = "flake-compat"; + rev = "5edf11c44bc78a0d334f6334cdaf7d60d732daab"; + type = "github"; + }; + "flake-compat_2" = { + flake = false; + narHash = "sha256-z9k3MfslLjWQfnjBtEtJZdq3H7kyi2kQtUThfTgdRk0="; + owner = "input-output-hk"; + repo = "flake-compat"; + rev = "45f2638735f8cdc40fe302742b79f248d23eb368"; + type = "github"; + }; + "hackage" = { + flake = false; + narHash = "sha256-aAn6YyEMPmNlQTY3XM2viwZP5+jSih2PXsJNl5I9Tw8="; + owner = "input-output-hk"; + repo = "hackage.nix"; + rev = "6262c828b6539dadc7a567e65be26bf3c45fda6c"; + type = "github"; + }; + "hackage-for-stackage" = { + flake = false; + narHash = "sha256-dmR6z5cDs9Jjnz4zNAdTdML5cHxeUJrFdozvsAd66UQ="; + owner = "input-output-hk"; + repo = "hackage.nix"; + rev = "30337ea718070b928e1c51454a85c51e035b3cad"; + type = "github"; + }; + "hackage-internal" = { + flake = false; + narHash = "sha256-iiafNoeLHwlSLQTyvy8nPe2t6g5AV4PPcpMeH/2/DLs="; + owner = "input-output-hk"; + repo = "hackage.nix"; + rev = "f7867baa8817fab296528f4a4ec39d1c7c4da4f3"; + type = "github"; + }; + "hackage-overlay-repo-tool" = { + flake = false; + narHash = "sha256-GKeke8FT9w2u6J9aI4eN3mOV0BURHiytQAEir4/4M1Q="; + owner = "bgamari"; + repo = "hackage-overlay-repo-tool"; + rev = "f60aa0d497961745a503ddea2adb0facb58376e8"; + type = "github"; + }; + "haskell-nix" = { + allRefs = true; + dir = "pins/haskell-nix"; + rev = "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e"; + submodules = true; + type = "git"; + url = "https://github.com/reflex-frp/nix-haskell.git"; + inputs = { + "HTTP" = { follows = "HTTP"; }; + "cabal-34" = { follows = "cabal-34"; }; + "cabal-36" = { follows = "cabal-36"; }; + "cabal-doctest" = { follows = "cabal-doctest"; }; + "cardano-shell" = { follows = "cardano-shell"; }; + "flake-compat" = { follows = "flake-compat_2"; }; + "hackage" = { follows = "hackage"; }; + "hackage-for-stackage" = { follows = "hackage-for-stackage"; }; + "hackage-internal" = { follows = "hackage-internal"; }; + "hackage-overlay-repo-tool" = { follows = "hackage-overlay-repo-tool"; }; + "head-hackage" = { follows = "head-hackage"; }; + "hls" = { follows = "hls"; }; + "hls-1.10" = { follows = "hls-1_10"; }; + "hls-2.0" = { follows = "hls-2_0"; }; + "hls-2.10" = { follows = "hls-2_10"; }; + "hls-2.11" = { follows = "hls-2_11"; }; + "hls-2.12" = { follows = "hls-2_12"; }; + "hls-2.2" = { follows = "hls-2_2"; }; + "hls-2.3" = { follows = "hls-2_3"; }; + "hls-2.4" = { follows = "hls-2_4"; }; + "hls-2.5" = { follows = "hls-2_5"; }; + "hls-2.6" = { follows = "hls-2_6"; }; + "hls-2.7" = { follows = "hls-2_7"; }; + "hls-2.8" = { follows = "hls-2_8"; }; + "hls-2.9" = { follows = "hls-2_9"; }; + "hpc-coveralls" = { follows = "hpc-coveralls"; }; + "hyper-linux" = { follows = "hyper-linux"; }; + "iserv-proxy" = { follows = "iserv-proxy"; }; + "nixpkgs" = { follows = "nixpkgs-unstable"; }; + "nixpkgs-2305" = { follows = "nixpkgs-2305"; }; + "nixpkgs-2311" = { follows = "nixpkgs-2311"; }; + "nixpkgs-2405" = { follows = "nixpkgs-2405"; }; + "nixpkgs-2411" = { follows = "nixpkgs-2411"; }; + "nixpkgs-2505" = { follows = "nixpkgs-2505"; }; + "nixpkgs-2511" = { follows = "nixpkgs-2511"; }; + "nixpkgs-2605" = { follows = "nixpkgs-2605"; }; + "nixpkgs-unstable" = { follows = "nixpkgs-unstable"; }; + "old-ghc-nix" = { follows = "old-ghc-nix"; }; + "stackage" = { follows = "stackage"; }; + }; + }; + "head-hackage" = { + flake = false; + host = "gitlab.haskell.org"; + narHash = "sha256-oifEa/JYg8ZLUtkbM8HVzKmqCcT9QxaDmG0ex2qT0Ng="; + owner = "ghc"; + repo = "head.hackage"; + rev = "a50bec6c7722f774415bc0f0a0e64f6e2b8989b7"; + type = "gitlab"; + }; + "hls" = { + flake = false; + narHash = "sha256-tuq3+Ip70yu89GswZ7DSINBpwRprnWnl6xDYnS4GOsc="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "682d6894c94087da5e566771f25311c47e145359"; + type = "github"; + }; + "hls-1_10" = { + flake = false; + narHash = "sha256-rc7iiUAcrHxwRM/s0ErEsSPxOR3u8t7DvFeWlMycWgo="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "b08691db779f7a35ff322b71e72a12f6e3376fd9"; + type = "github"; + }; + "hls-2_0" = { + flake = false; + narHash = "sha256-OHXlgRzs/kuJH8q7Sxh507H+0Rb8b7VOiPAjcY9sM1k="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "783905f211ac63edf982dd1889c671653327e441"; + type = "github"; + }; + "hls-2_10" = { + flake = false; + narHash = "sha256-q4kDFyJDDeoGqfEtrZRx4iqMVEC2MOzCToWsFY+TOzY="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "2318c61db3a01e03700bd4b05665662929b7fe8b"; + type = "github"; + }; + "hls-2_11" = { + flake = false; + narHash = "sha256-/MmtpF8+FyQlwfKHqHK05BdsxC9LHV70d/FiMM7pzBM="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "46ef4523ea4949f47f6d2752476239f1c6d806fe"; + type = "github"; + }; + "hls-2_12" = { + flake = false; + narHash = "sha256-xkI8MIIVEVARskfWbGAgP5sHG/lyeKnkm0LIOJ19X5w="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "7d983de4fa7ff54369f6dd31444bdb9869aec83e"; + type = "github"; + }; + "hls-2_2" = { + flake = false; + narHash = "sha256-8DGIyz5GjuCFmohY6Fa79hHA/p1iIqubfJUTGQElbNk="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "b30f4b6cf5822f3112c35d14a0cba51f3fe23b85"; + type = "github"; + }; + "hls-2_3" = { + flake = false; + narHash = "sha256-tR58doOs3DncFehHwCLczJgntyG/zlsSd7DgDgMPOkI="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "458ccdb55c9ea22cd5d13ec3051aaefb295321be"; + type = "github"; + }; + "hls-2_4" = { + flake = false; + narHash = "sha256-YHXSkdz53zd0fYGIYOgLt6HrA0eaRJi9mXVqDgmvrjk="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "54507ef7e85fa8e9d0eb9a669832a3287ffccd57"; + type = "github"; + }; + "hls-2_5" = { + flake = false; + narHash = "sha256-fyiR9TaHGJIIR0UmcCb73Xv9TJq3ht2ioxQ2mT7kVdc="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "27f8c3d3892e38edaef5bea3870161815c4d014c"; + type = "github"; + }; + "hls-2_6" = { + flake = false; + narHash = "sha256-+P87oLdlPyMw8Mgoul7HMWdEvWP/fNlo8jyNtwME8E8="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "6e0b342fa0327e628610f2711f8c3e4eaaa08b1e"; + type = "github"; + }; + "hls-2_7" = { + flake = false; + narHash = "sha256-LfJ+TBcBFq/XKoiNI7pc4VoHg4WmuzsFxYJ3Fu+Jf+M="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "50322b0a4aefb27adc5ec42f5055aaa8f8e38001"; + type = "github"; + }; + "hls-2_8" = { + flake = false; + narHash = "sha256-Vi/iUt2pWyUJlo9VrYgTcbRviWE0cFO6rmGi9rmALw0="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "dd1be1beb16700de59e0d6801957290bcf956a0a"; + type = "github"; + }; + "hls-2_9" = { + flake = false; + narHash = "sha256-wy348++MiMm/xwtI9M3vVpqj2qfGgnDcZIGXw8sF1sA="; + owner = "haskell"; + repo = "haskell-language-server"; + rev = "90319a7e62ab93ab65a95f8f2bcf537e34dae76a"; + type = "github"; + }; + "hpc-coveralls" = { + flake = false; + narHash = "sha256-8uqsEtivphgZWYeUo5RDUhp6bO9j2vaaProQxHBltQk="; + owner = "sevanspowell"; + repo = "hpc-coveralls"; + rev = "14df0f7d229f4cd2e79f8eabb1a740097fdfa430"; + type = "github"; + }; + "hyper-linux" = { + narHash = "sha256-041m8HOyieDscFuzbgC764K+LTi4pSJH5+HwTSveJT8="; + owner = "zw3rk"; + repo = "hyper-linux"; + rev = "41cea39c8d8243d729991d0c26515f6bfe7be7fb"; + type = "github"; + inputs = { + "nixpkgs" = { follows = "nixpkgs-unstable"; }; + }; + }; + "iserv-proxy" = { + flake = false; + narHash = "sha256-BXCMjVXEs40oVlNicxD+nrVSvf9R0KT+dLl0mOdGm0I="; + owner = "stable-haskell"; + repo = "iserv-proxy"; + rev = "5c483b26074f2b9b8056ce71e7a3c44c02c4d7c0"; + type = "github"; + }; + "nixpkgs" = { + allRefs = true; + dir = "pins/nixpkgs"; + rev = "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e"; + submodules = true; + type = "git"; + url = "https://github.com/reflex-frp/nix-haskell.git"; + inputs = { + "upstream" = { follows = "upstream"; }; + }; + }; + "nixpkgs-2305" = { + narHash = "sha256-K5eJHmL1/kev6WuqyqqbS1cdNnSidIZ3jeqJ7GbrYnQ="; + owner = "NixOS"; + repo = "nixpkgs"; + rev = "a1982c92d8980a0114372973cbdfe0a307f1bdea"; + type = "github"; + }; + "nixpkgs-2311" = { + narHash = "sha256-gvFhEf5nszouwLAkT9nWsDzocUTqLWHuL++dvNjMp9I="; + owner = "NixOS"; + repo = "nixpkgs"; + rev = "7144d6241f02d171d25fba3edeaf15e0f2592105"; + type = "github"; + }; + "nixpkgs-2405" = { + narHash = "sha256-HB/FA0+1gpSs8+/boEavrGJH+Eq08/R2wWNph1sM1Dg="; + owner = "NixOS"; + repo = "nixpkgs"; + rev = "1e7a8f391f1a490460760065fa0630b5520f9cf8"; + type = "github"; + }; + "nixpkgs-2411" = { + narHash = "sha256-kNf+obkpJZWar7HZymXZbW+Rlk3HTEIMlpc6FCNz0Ds="; + owner = "NixOS"; + repo = "nixpkgs"; + rev = "5ab036a8d97cb9476fbe81b09076e6e91d15e1b6"; + type = "github"; + }; + "nixpkgs-2505" = { + narHash = "sha256-jc21hKogFnxU7KXSVTRmxC7u5D4RHwm9BAvDf5/Z1Uo="; + owner = "NixOS"; + repo = "nixpkgs"; + rev = "3e3f3c7f9977dc123c23ee21e8085ed63daf8c37"; + type = "github"; + }; + "nixpkgs-2511" = { + narHash = "sha256-ESJ4VgytmAt+98YLM8466luln4HyEZ9Q36b9+Bb4P5w="; + owner = "NixOS"; + repo = "nixpkgs"; + rev = "0921fdb3e13e40fe25fbc52b89661a9d6d32ac68"; + type = "github"; + }; + "nixpkgs-2605" = { + narHash = "sha256-+//qXhkXCKTFoVCHAYhoEP1ZnPSx/b4IHdLI1ZMz3UU="; + owner = "NixOS"; + repo = "nixpkgs"; + rev = "36173dbc6ff2b383c4d03b002fd1ea58e2e4dbcd"; + type = "github"; + }; + "nixpkgs-unstable" = { + narHash = "sha256-Thn0OE71NF80ZfOMGCgJvKtbCcnnz0fToT/qsvb/Gtc="; + owner = "NixOS"; + repo = "nixpkgs"; + rev = "d357a2b54f0b6dc4aeb4e993190a52cf151b6f24"; + type = "github"; + }; + "old-ghc-nix" = { + flake = false; + narHash = "sha256-sIKgO+z7tj4lw3u6oBZxqIhDrzSkvpHtv0Kki+lh9Fg="; + owner = "angerman"; + repo = "old-ghc-nix"; + rev = "af48a7a7353e418119b6dfe3cd1463a657f342b8"; + type = "github"; + }; + "sandstone" = { + allRefs = true; + dir = "pins/sandstone"; + flake = false; + rev = "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e"; + submodules = true; + type = "git"; + url = "https://github.com/reflex-frp/nix-haskell.git"; + }; + "stackage" = { + flake = false; + narHash = "sha256-1XjknkUH8ENHQaoWSO+M3US7/vJsEYjMgBVdci9DBmI="; + owner = "input-output-hk"; + repo = "stackage.nix"; + rev = "2b2df46b0dbe0f415c3c69a42f922f9f2a473e91"; + type = "github"; + }; + "upstream" = { + narHash = "sha256-XuAV2cUwaod3Bt4XFVqiXz3v1w2ex16W6Sv4S7EWres="; + owner = "NixOS"; + repo = "nixpkgs"; + rev = "ac588ef1c914865dad517b337ea0eb9694a4021c"; + type = "github"; + }; + }; + outputs = inputs: inputs."upstream_2".outputs // { src = inputs."upstream_2"; }; +} diff --git a/deps/nix-haskell/github.json b/deps/nix-haskell/github.json new file mode 100644 index 00000000..98c15f94 --- /dev/null +++ b/deps/nix-haskell/github.json @@ -0,0 +1,8 @@ +{ + "owner": "reflex-frp", + "repo": "nix-haskell", + "fetchSubmodules": true, + "private": false, + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "sha256": "18qc0rfs06dm334z1ygvdvrr8zjfrkkfnx5vmnza85fz81n12avf" +} diff --git a/deps/nix-haskell/thunk.nix b/deps/nix-haskell/thunk.nix new file mode 100644 index 00000000..0a5fa608 --- /dev/null +++ b/deps/nix-haskell/thunk.nix @@ -0,0 +1,34 @@ +# DO NOT HAND-EDIT THIS FILE +let fetch = { private ? false, fetchSubmodules ? false, branch ? null, owner, repo, rev, sha256, ... }: + let hashArgs = + if builtins ? convertHash + then { + narHash = builtins.convertHash { + hash = sha256; + hashAlgo = "sha256"; + toHashFormat = "sri"; + }; + } + else {}; + in if !fetchSubmodules && !private + then builtins.fetchTarball { + url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; + inherit sha256; + } + else if builtins ? currentSystem + then (import (builtins.fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/3aad50c30c826430b0270fcf8264c8c41b005403.tar.gz"; + sha256 = "0xwqsf08sywd23x0xvw4c4ghq0l28w2ki22h0bdn766i16z9q2gr"; + }) {}).fetchFromGitHub { + inherit owner repo rev sha256 fetchSubmodules private; + } + else builtins.fetchTree ({ + type = "git"; + url = "${if private then "ssh://git@github.com" else "https://github.com"}/${owner}/${repo}.git"; + inherit rev; + submodules = fetchSubmodules; + ${if branch == null then null else "ref"} = branch; + allRefs = branch == null; + } // hashArgs); + json = builtins.fromJSON (builtins.readFile ./github.json); +in fetch json \ No newline at end of file diff --git a/nix/deps/nixpkgs/default.nix b/deps/style.hs/default.nix similarity index 100% rename from nix/deps/nixpkgs/default.nix rename to deps/style.hs/default.nix diff --git a/deps/style.hs/flake.lock b/deps/style.hs/flake.lock new file mode 100644 index 00000000..7bbae3d2 --- /dev/null +++ b/deps/style.hs/flake.lock @@ -0,0 +1,71 @@ +{ + "nodes": { + "flake-compat": { + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1781216227, + "narHash": "sha256-9mUW6gNwoN2SWc/l0fW4svPNOulXLl8ijqKyeSOGgJE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a0374025a863d007d98e3297f6aa46cc3141c2f0", + "type": "github" + }, + "original": { + "narHash": "sha256-9mUW6gNwoN2SWc/l0fW4svPNOulXLl8ijqKyeSOGgJE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a0374025a863d007d98e3297f6aa46cc3141c2f0", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": "nixpkgs", + "upstream": "upstream" + } + }, + "upstream": { + "inputs": { + "flake-compat": [ + "flake-compat" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1792691575, + "narHash": "sha256-7PF0BVC728ZBxRpeGN0LnOnsUoL15TrdE6bsRG9SkUw=", + "owner": "obsidiansystems", + "repo": "style.hs", + "rev": "417c71ee50898b700221c0ef10ccc6c1befb4500", + "type": "github" + }, + "original": { + "owner": "obsidiansystems", + "repo": "style.hs", + "rev": "417c71ee50898b700221c0ef10ccc6c1befb4500", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/deps/style.hs/flake.nix b/deps/style.hs/flake.nix new file mode 100644 index 00000000..7d47679d --- /dev/null +++ b/deps/style.hs/flake.nix @@ -0,0 +1,30 @@ +# DO NOT HAND-EDIT THIS FILE +{ + inputs = { + "upstream" = { + owner = "obsidiansystems"; + repo = "style.hs"; + rev = "417c71ee50898b700221c0ef10ccc6c1befb4500"; + type = "github"; + inputs = { + "flake-compat" = { follows = "flake-compat"; }; + "nixpkgs" = { follows = "nixpkgs"; }; + }; + }; + "flake-compat" = { + narHash = "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns="; + owner = "NixOS"; + repo = "flake-compat"; + rev = "5edf11c44bc78a0d334f6334cdaf7d60d732daab"; + type = "github"; + }; + "nixpkgs" = { + narHash = "sha256-9mUW6gNwoN2SWc/l0fW4svPNOulXLl8ijqKyeSOGgJE="; + owner = "NixOS"; + repo = "nixpkgs"; + rev = "a0374025a863d007d98e3297f6aa46cc3141c2f0"; + type = "github"; + }; + }; + outputs = inputs: inputs."upstream".outputs // { src = inputs."upstream"; }; +} diff --git a/deps/style.hs/github.json b/deps/style.hs/github.json new file mode 100644 index 00000000..a4cd357d --- /dev/null +++ b/deps/style.hs/github.json @@ -0,0 +1,8 @@ +{ + "owner": "obsidiansystems", + "repo": "style.hs", + "fetchSubmodules": false, + "private": false, + "rev": "417c71ee50898b700221c0ef10ccc6c1befb4500", + "sha256": "0k4ia9pl9v562gfkmrgmh99frscw1gfihphsqm0wdnxva02p9wgc" +} diff --git a/deps/style.hs/thunk.nix b/deps/style.hs/thunk.nix new file mode 100644 index 00000000..0a5fa608 --- /dev/null +++ b/deps/style.hs/thunk.nix @@ -0,0 +1,34 @@ +# DO NOT HAND-EDIT THIS FILE +let fetch = { private ? false, fetchSubmodules ? false, branch ? null, owner, repo, rev, sha256, ... }: + let hashArgs = + if builtins ? convertHash + then { + narHash = builtins.convertHash { + hash = sha256; + hashAlgo = "sha256"; + toHashFormat = "sri"; + }; + } + else {}; + in if !fetchSubmodules && !private + then builtins.fetchTarball { + url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; + inherit sha256; + } + else if builtins ? currentSystem + then (import (builtins.fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/3aad50c30c826430b0270fcf8264c8c41b005403.tar.gz"; + sha256 = "0xwqsf08sywd23x0xvw4c4ghq0l28w2ki22h0bdn766i16z9q2gr"; + }) {}).fetchFromGitHub { + inherit owner repo rev sha256 fetchSubmodules private; + } + else builtins.fetchTree ({ + type = "git"; + url = "${if private then "ssh://git@github.com" else "https://github.com"}/${owner}/${repo}.git"; + inherit rev; + submodules = fetchSubmodules; + ${if branch == null then null else "ref"} = branch; + allRefs = branch == null; + } // hashArgs); + json = builtins.fromJSON (builtins.readFile ./github.json); +in fetch json \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..cd3f1b7d --- /dev/null +++ b/flake.lock @@ -0,0 +1,1135 @@ +{ + "nodes": { + "HTTP": { + "flake": false, + "locked": { + "lastModified": 1451647621, + "narHash": "sha256-oHIyw3x0iKBexEo49YeUDV1k74ZtyYKGR2gNJXXRxts=", + "owner": "phadej", + "repo": "HTTP", + "rev": "9bc0996d412fef1787449d841277ef663ad9a915", + "type": "github" + }, + "original": { + "narHash": "sha256-oHIyw3x0iKBexEo49YeUDV1k74ZtyYKGR2gNJXXRxts=", + "owner": "phadej", + "repo": "HTTP", + "rev": "9bc0996d412fef1787449d841277ef663ad9a915", + "type": "github" + } + }, + "cabal-34": { + "flake": false, + "locked": { + "lastModified": 1645834128, + "narHash": "sha256-wG3d+dOt14z8+ydz4SL7pwGfe7SiimxcD/LOuPCV6xM=", + "owner": "haskell", + "repo": "cabal", + "rev": "5ff598c67f53f7c4f48e31d722ba37172230c462", + "type": "github" + }, + "original": { + "narHash": "sha256-wG3d+dOt14z8+ydz4SL7pwGfe7SiimxcD/LOuPCV6xM=", + "owner": "haskell", + "repo": "cabal", + "rev": "5ff598c67f53f7c4f48e31d722ba37172230c462", + "type": "github" + } + }, + "cabal-36": { + "flake": false, + "locked": { + "lastModified": 1669081697, + "narHash": "sha256-I5or+V7LZvMxfbYgZATU4awzkicBwwok4mVoje+sGmU=", + "owner": "haskell", + "repo": "cabal", + "rev": "8fd619e33d34924a94e691c5fea2c42f0fc7f144", + "type": "github" + }, + "original": { + "narHash": "sha256-I5or+V7LZvMxfbYgZATU4awzkicBwwok4mVoje+sGmU=", + "owner": "haskell", + "repo": "cabal", + "rev": "8fd619e33d34924a94e691c5fea2c42f0fc7f144", + "type": "github" + } + }, + "cabal-doctest": { + "flake": false, + "locked": { + "lastModified": 1787831028, + "narHash": "sha256-YUSquN8tlV59hWoArmP5wxHxK8lIjcmZofxNQTMC4IQ=", + "owner": "stable-haskell", + "repo": "cabal-doctest", + "rev": "641cda5a4590f2384568a9598713f3039b99258d", + "type": "github" + }, + "original": { + "narHash": "sha256-YUSquN8tlV59hWoArmP5wxHxK8lIjcmZofxNQTMC4IQ=", + "owner": "stable-haskell", + "repo": "cabal-doctest", + "rev": "641cda5a4590f2384568a9598713f3039b99258d", + "type": "github" + } + }, + "cardano-shell": { + "flake": false, + "locked": { + "lastModified": 1608537748, + "narHash": "sha256-PulY1GfiMgKVnBci3ex4ptk2UNYMXqGjJOxcPy2KYT4=", + "owner": "input-output-hk", + "repo": "cardano-shell", + "rev": "9392c75087cb9a3d453998f4230930dea3a95725", + "type": "github" + }, + "original": { + "narHash": "sha256-PulY1GfiMgKVnBci3ex4ptk2UNYMXqGjJOxcPy2KYT4=", + "owner": "input-output-hk", + "repo": "cardano-shell", + "rev": "9392c75087cb9a3d453998f4230930dea3a95725", + "type": "github" + } + }, + "flake-compat": { + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1672831974, + "narHash": "sha256-z9k3MfslLjWQfnjBtEtJZdq3H7kyi2kQtUThfTgdRk0=", + "owner": "input-output-hk", + "repo": "flake-compat", + "rev": "45f2638735f8cdc40fe302742b79f248d23eb368", + "type": "github" + }, + "original": { + "narHash": "sha256-z9k3MfslLjWQfnjBtEtJZdq3H7kyi2kQtUThfTgdRk0=", + "owner": "input-output-hk", + "repo": "flake-compat", + "rev": "45f2638735f8cdc40fe302742b79f248d23eb368", + "type": "github" + } + }, + "flake-compat_3": { + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + } + }, + "hackage": { + "flake": false, + "locked": { + "lastModified": 1794026965, + "narHash": "sha256-aAn6YyEMPmNlQTY3XM2viwZP5+jSih2PXsJNl5I9Tw8=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "6262c828b6539dadc7a567e65be26bf3c45fda6c", + "type": "github" + }, + "original": { + "narHash": "sha256-aAn6YyEMPmNlQTY3XM2viwZP5+jSih2PXsJNl5I9Tw8=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "6262c828b6539dadc7a567e65be26bf3c45fda6c", + "type": "github" + } + }, + "hackage-for-stackage": { + "flake": false, + "locked": { + "lastModified": 1794026940, + "narHash": "sha256-dmR6z5cDs9Jjnz4zNAdTdML5cHxeUJrFdozvsAd66UQ=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "30337ea718070b928e1c51454a85c51e035b3cad", + "type": "github" + }, + "original": { + "narHash": "sha256-dmR6z5cDs9Jjnz4zNAdTdML5cHxeUJrFdozvsAd66UQ=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "30337ea718070b928e1c51454a85c51e035b3cad", + "type": "github" + } + }, + "hackage-internal": { + "flake": false, + "locked": { + "lastModified": 1750307553, + "narHash": "sha256-iiafNoeLHwlSLQTyvy8nPe2t6g5AV4PPcpMeH/2/DLs=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "f7867baa8817fab296528f4a4ec39d1c7c4da4f3", + "type": "github" + }, + "original": { + "narHash": "sha256-iiafNoeLHwlSLQTyvy8nPe2t6g5AV4PPcpMeH/2/DLs=", + "owner": "input-output-hk", + "repo": "hackage.nix", + "rev": "f7867baa8817fab296528f4a4ec39d1c7c4da4f3", + "type": "github" + } + }, + "hackage-overlay-repo-tool": { + "flake": false, + "locked": { + "lastModified": 1671663228, + "narHash": "sha256-GKeke8FT9w2u6J9aI4eN3mOV0BURHiytQAEir4/4M1Q=", + "owner": "bgamari", + "repo": "hackage-overlay-repo-tool", + "rev": "f60aa0d497961745a503ddea2adb0facb58376e8", + "type": "github" + }, + "original": { + "narHash": "sha256-GKeke8FT9w2u6J9aI4eN3mOV0BURHiytQAEir4/4M1Q=", + "owner": "bgamari", + "repo": "hackage-overlay-repo-tool", + "rev": "f60aa0d497961745a503ddea2adb0facb58376e8", + "type": "github" + } + }, + "haskell-nix": { + "inputs": { + "HTTP": [ + "nix-haskell", + "HTTP" + ], + "cabal-34": [ + "nix-haskell", + "cabal-34" + ], + "cabal-36": [ + "nix-haskell", + "cabal-36" + ], + "cabal-doctest": [ + "nix-haskell", + "cabal-doctest" + ], + "cardano-shell": [ + "nix-haskell", + "cardano-shell" + ], + "flake-compat": [ + "nix-haskell", + "flake-compat_2" + ], + "hackage": [ + "nix-haskell", + "hackage" + ], + "hackage-for-stackage": [ + "nix-haskell", + "hackage-for-stackage" + ], + "hackage-internal": [ + "nix-haskell", + "hackage-internal" + ], + "hackage-overlay-repo-tool": [ + "nix-haskell", + "hackage-overlay-repo-tool" + ], + "head-hackage": [ + "nix-haskell", + "head-hackage" + ], + "hls": [ + "nix-haskell", + "hls" + ], + "hls-1.10": [ + "nix-haskell", + "hls-1_10" + ], + "hls-2.0": [ + "nix-haskell", + "hls-2_0" + ], + "hls-2.10": [ + "nix-haskell", + "hls-2_10" + ], + "hls-2.11": [ + "nix-haskell", + "hls-2_11" + ], + "hls-2.12": [ + "nix-haskell", + "hls-2_12" + ], + "hls-2.2": [ + "nix-haskell", + "hls-2_2" + ], + "hls-2.3": [ + "nix-haskell", + "hls-2_3" + ], + "hls-2.4": [ + "nix-haskell", + "hls-2_4" + ], + "hls-2.5": [ + "nix-haskell", + "hls-2_5" + ], + "hls-2.6": [ + "nix-haskell", + "hls-2_6" + ], + "hls-2.7": [ + "nix-haskell", + "hls-2_7" + ], + "hls-2.8": [ + "nix-haskell", + "hls-2_8" + ], + "hls-2.9": [ + "nix-haskell", + "hls-2_9" + ], + "hpc-coveralls": [ + "nix-haskell", + "hpc-coveralls" + ], + "hyper-linux": [ + "nix-haskell", + "hyper-linux" + ], + "iserv-proxy": [ + "nix-haskell", + "iserv-proxy" + ], + "nixpkgs": [ + "nix-haskell", + "nixpkgs-unstable" + ], + "nixpkgs-2305": [ + "nix-haskell", + "nixpkgs-2305" + ], + "nixpkgs-2311": [ + "nix-haskell", + "nixpkgs-2311" + ], + "nixpkgs-2405": [ + "nix-haskell", + "nixpkgs-2405" + ], + "nixpkgs-2411": [ + "nix-haskell", + "nixpkgs-2411" + ], + "nixpkgs-2505": [ + "nix-haskell", + "nixpkgs-2505" + ], + "nixpkgs-2511": [ + "nix-haskell", + "nixpkgs-2511" + ], + "nixpkgs-2605": [ + "nix-haskell", + "nixpkgs-2605" + ], + "nixpkgs-unstable": [ + "nix-haskell", + "nixpkgs-unstable" + ], + "old-ghc-nix": [ + "nix-haskell", + "old-ghc-nix" + ], + "stackage": [ + "nix-haskell", + "stackage" + ] + }, + "locked": { + "allRefs": true, + "dir": "pins/haskell-nix", + "lastModified": 1794571666, + "narHash": "sha256-bisRbEDfFaS+rbt06+bMTn6U8277+fDJGLUZoF0GDKM=", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + }, + "original": { + "allRefs": true, + "dir": "pins/haskell-nix", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + } + }, + "head-hackage": { + "flake": false, + "locked": { + "host": "gitlab.haskell.org", + "lastModified": 1780387533, + "narHash": "sha256-oifEa/JYg8ZLUtkbM8HVzKmqCcT9QxaDmG0ex2qT0Ng=", + "owner": "ghc", + "repo": "head.hackage", + "rev": "a50bec6c7722f774415bc0f0a0e64f6e2b8989b7", + "type": "gitlab" + }, + "original": { + "host": "gitlab.haskell.org", + "narHash": "sha256-oifEa/JYg8ZLUtkbM8HVzKmqCcT9QxaDmG0ex2qT0Ng=", + "owner": "ghc", + "repo": "head.hackage", + "rev": "a50bec6c7722f774415bc0f0a0e64f6e2b8989b7", + "type": "gitlab" + } + }, + "hls": { + "flake": false, + "locked": { + "lastModified": 1741604408, + "narHash": "sha256-tuq3+Ip70yu89GswZ7DSINBpwRprnWnl6xDYnS4GOsc=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "682d6894c94087da5e566771f25311c47e145359", + "type": "github" + }, + "original": { + "narHash": "sha256-tuq3+Ip70yu89GswZ7DSINBpwRprnWnl6xDYnS4GOsc=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "682d6894c94087da5e566771f25311c47e145359", + "type": "github" + } + }, + "hls-1_10": { + "flake": false, + "locked": { + "lastModified": 1680000865, + "narHash": "sha256-rc7iiUAcrHxwRM/s0ErEsSPxOR3u8t7DvFeWlMycWgo=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "b08691db779f7a35ff322b71e72a12f6e3376fd9", + "type": "github" + }, + "original": { + "narHash": "sha256-rc7iiUAcrHxwRM/s0ErEsSPxOR3u8t7DvFeWlMycWgo=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "b08691db779f7a35ff322b71e72a12f6e3376fd9", + "type": "github" + } + }, + "hls-2_0": { + "flake": false, + "locked": { + "lastModified": 1687698105, + "narHash": "sha256-OHXlgRzs/kuJH8q7Sxh507H+0Rb8b7VOiPAjcY9sM1k=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "783905f211ac63edf982dd1889c671653327e441", + "type": "github" + }, + "original": { + "narHash": "sha256-OHXlgRzs/kuJH8q7Sxh507H+0Rb8b7VOiPAjcY9sM1k=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "783905f211ac63edf982dd1889c671653327e441", + "type": "github" + } + }, + "hls-2_10": { + "flake": false, + "locked": { + "lastModified": 1743069404, + "narHash": "sha256-q4kDFyJDDeoGqfEtrZRx4iqMVEC2MOzCToWsFY+TOzY=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "2318c61db3a01e03700bd4b05665662929b7fe8b", + "type": "github" + }, + "original": { + "narHash": "sha256-q4kDFyJDDeoGqfEtrZRx4iqMVEC2MOzCToWsFY+TOzY=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "2318c61db3a01e03700bd4b05665662929b7fe8b", + "type": "github" + } + }, + "hls-2_11": { + "flake": false, + "locked": { + "lastModified": 1747306193, + "narHash": "sha256-/MmtpF8+FyQlwfKHqHK05BdsxC9LHV70d/FiMM7pzBM=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "46ef4523ea4949f47f6d2752476239f1c6d806fe", + "type": "github" + }, + "original": { + "narHash": "sha256-/MmtpF8+FyQlwfKHqHK05BdsxC9LHV70d/FiMM7pzBM=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "46ef4523ea4949f47f6d2752476239f1c6d806fe", + "type": "github" + } + }, + "hls-2_12": { + "flake": false, + "locked": { + "lastModified": 1758709460, + "narHash": "sha256-xkI8MIIVEVARskfWbGAgP5sHG/lyeKnkm0LIOJ19X5w=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "7d983de4fa7ff54369f6dd31444bdb9869aec83e", + "type": "github" + }, + "original": { + "narHash": "sha256-xkI8MIIVEVARskfWbGAgP5sHG/lyeKnkm0LIOJ19X5w=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "7d983de4fa7ff54369f6dd31444bdb9869aec83e", + "type": "github" + } + }, + "hls-2_2": { + "flake": false, + "locked": { + "lastModified": 1693064058, + "narHash": "sha256-8DGIyz5GjuCFmohY6Fa79hHA/p1iIqubfJUTGQElbNk=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "b30f4b6cf5822f3112c35d14a0cba51f3fe23b85", + "type": "github" + }, + "original": { + "narHash": "sha256-8DGIyz5GjuCFmohY6Fa79hHA/p1iIqubfJUTGQElbNk=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "b30f4b6cf5822f3112c35d14a0cba51f3fe23b85", + "type": "github" + } + }, + "hls-2_3": { + "flake": false, + "locked": { + "lastModified": 1695910642, + "narHash": "sha256-tR58doOs3DncFehHwCLczJgntyG/zlsSd7DgDgMPOkI=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "458ccdb55c9ea22cd5d13ec3051aaefb295321be", + "type": "github" + }, + "original": { + "narHash": "sha256-tR58doOs3DncFehHwCLczJgntyG/zlsSd7DgDgMPOkI=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "458ccdb55c9ea22cd5d13ec3051aaefb295321be", + "type": "github" + } + }, + "hls-2_4": { + "flake": false, + "locked": { + "lastModified": 1699862708, + "narHash": "sha256-YHXSkdz53zd0fYGIYOgLt6HrA0eaRJi9mXVqDgmvrjk=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "54507ef7e85fa8e9d0eb9a669832a3287ffccd57", + "type": "github" + }, + "original": { + "narHash": "sha256-YHXSkdz53zd0fYGIYOgLt6HrA0eaRJi9mXVqDgmvrjk=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "54507ef7e85fa8e9d0eb9a669832a3287ffccd57", + "type": "github" + } + }, + "hls-2_5": { + "flake": false, + "locked": { + "lastModified": 1701080174, + "narHash": "sha256-fyiR9TaHGJIIR0UmcCb73Xv9TJq3ht2ioxQ2mT7kVdc=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "27f8c3d3892e38edaef5bea3870161815c4d014c", + "type": "github" + }, + "original": { + "narHash": "sha256-fyiR9TaHGJIIR0UmcCb73Xv9TJq3ht2ioxQ2mT7kVdc=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "27f8c3d3892e38edaef5bea3870161815c4d014c", + "type": "github" + } + }, + "hls-2_6": { + "flake": false, + "locked": { + "lastModified": 1705325287, + "narHash": "sha256-+P87oLdlPyMw8Mgoul7HMWdEvWP/fNlo8jyNtwME8E8=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "6e0b342fa0327e628610f2711f8c3e4eaaa08b1e", + "type": "github" + }, + "original": { + "narHash": "sha256-+P87oLdlPyMw8Mgoul7HMWdEvWP/fNlo8jyNtwME8E8=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "6e0b342fa0327e628610f2711f8c3e4eaaa08b1e", + "type": "github" + } + }, + "hls-2_7": { + "flake": false, + "locked": { + "lastModified": 1708965829, + "narHash": "sha256-LfJ+TBcBFq/XKoiNI7pc4VoHg4WmuzsFxYJ3Fu+Jf+M=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "50322b0a4aefb27adc5ec42f5055aaa8f8e38001", + "type": "github" + }, + "original": { + "narHash": "sha256-LfJ+TBcBFq/XKoiNI7pc4VoHg4WmuzsFxYJ3Fu+Jf+M=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "50322b0a4aefb27adc5ec42f5055aaa8f8e38001", + "type": "github" + } + }, + "hls-2_8": { + "flake": false, + "locked": { + "lastModified": 1715153580, + "narHash": "sha256-Vi/iUt2pWyUJlo9VrYgTcbRviWE0cFO6rmGi9rmALw0=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "dd1be1beb16700de59e0d6801957290bcf956a0a", + "type": "github" + }, + "original": { + "narHash": "sha256-Vi/iUt2pWyUJlo9VrYgTcbRviWE0cFO6rmGi9rmALw0=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "dd1be1beb16700de59e0d6801957290bcf956a0a", + "type": "github" + } + }, + "hls-2_9": { + "flake": false, + "locked": { + "lastModified": 1719993701, + "narHash": "sha256-wy348++MiMm/xwtI9M3vVpqj2qfGgnDcZIGXw8sF1sA=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "90319a7e62ab93ab65a95f8f2bcf537e34dae76a", + "type": "github" + }, + "original": { + "narHash": "sha256-wy348++MiMm/xwtI9M3vVpqj2qfGgnDcZIGXw8sF1sA=", + "owner": "haskell", + "repo": "haskell-language-server", + "rev": "90319a7e62ab93ab65a95f8f2bcf537e34dae76a", + "type": "github" + } + }, + "hpc-coveralls": { + "flake": false, + "locked": { + "lastModified": 1607498076, + "narHash": "sha256-8uqsEtivphgZWYeUo5RDUhp6bO9j2vaaProQxHBltQk=", + "owner": "sevanspowell", + "repo": "hpc-coveralls", + "rev": "14df0f7d229f4cd2e79f8eabb1a740097fdfa430", + "type": "github" + }, + "original": { + "narHash": "sha256-8uqsEtivphgZWYeUo5RDUhp6bO9j2vaaProQxHBltQk=", + "owner": "sevanspowell", + "repo": "hpc-coveralls", + "rev": "14df0f7d229f4cd2e79f8eabb1a740097fdfa430", + "type": "github" + } + }, + "hyper-linux": { + "inputs": { + "nixpkgs": [ + "nix-haskell", + "nixpkgs-unstable" + ] + }, + "locked": { + "lastModified": 1773548649, + "narHash": "sha256-041m8HOyieDscFuzbgC764K+LTi4pSJH5+HwTSveJT8=", + "owner": "zw3rk", + "repo": "hyper-linux", + "rev": "41cea39c8d8243d729991d0c26515f6bfe7be7fb", + "type": "github" + }, + "original": { + "narHash": "sha256-041m8HOyieDscFuzbgC764K+LTi4pSJH5+HwTSveJT8=", + "owner": "zw3rk", + "repo": "hyper-linux", + "rev": "41cea39c8d8243d729991d0c26515f6bfe7be7fb", + "type": "github" + } + }, + "iserv-proxy": { + "flake": false, + "locked": { + "lastModified": 1793394322, + "narHash": "sha256-BXCMjVXEs40oVlNicxD+nrVSvf9R0KT+dLl0mOdGm0I=", + "owner": "stable-haskell", + "repo": "iserv-proxy", + "rev": "5c483b26074f2b9b8056ce71e7a3c44c02c4d7c0", + "type": "github" + }, + "original": { + "narHash": "sha256-BXCMjVXEs40oVlNicxD+nrVSvf9R0KT+dLl0mOdGm0I=", + "owner": "stable-haskell", + "repo": "iserv-proxy", + "rev": "5c483b26074f2b9b8056ce71e7a3c44c02c4d7c0", + "type": "github" + } + }, + "nix-haskell": { + "inputs": { + "HTTP": "HTTP", + "cabal-34": "cabal-34", + "cabal-36": "cabal-36", + "cabal-doctest": "cabal-doctest", + "cardano-shell": "cardano-shell", + "flake-compat": "flake-compat", + "flake-compat_2": "flake-compat_2", + "hackage": "hackage", + "hackage-for-stackage": "hackage-for-stackage", + "hackage-internal": "hackage-internal", + "hackage-overlay-repo-tool": "hackage-overlay-repo-tool", + "haskell-nix": "haskell-nix", + "head-hackage": "head-hackage", + "hls": "hls", + "hls-1_10": "hls-1_10", + "hls-2_0": "hls-2_0", + "hls-2_10": "hls-2_10", + "hls-2_11": "hls-2_11", + "hls-2_12": "hls-2_12", + "hls-2_2": "hls-2_2", + "hls-2_3": "hls-2_3", + "hls-2_4": "hls-2_4", + "hls-2_5": "hls-2_5", + "hls-2_6": "hls-2_6", + "hls-2_7": "hls-2_7", + "hls-2_8": "hls-2_8", + "hls-2_9": "hls-2_9", + "hpc-coveralls": "hpc-coveralls", + "hyper-linux": "hyper-linux", + "iserv-proxy": "iserv-proxy", + "nixpkgs": "nixpkgs", + "nixpkgs-2305": "nixpkgs-2305", + "nixpkgs-2311": "nixpkgs-2311", + "nixpkgs-2405": "nixpkgs-2405", + "nixpkgs-2411": "nixpkgs-2411", + "nixpkgs-2505": "nixpkgs-2505", + "nixpkgs-2511": "nixpkgs-2511", + "nixpkgs-2605": "nixpkgs-2605", + "nixpkgs-unstable": "nixpkgs-unstable", + "old-ghc-nix": "old-ghc-nix", + "sandstone": "sandstone", + "stackage": "stackage", + "upstream": "upstream", + "upstream_2": "upstream_2" + }, + "locked": { + "path": "deps/nix-haskell", + "type": "path" + }, + "original": { + "path": "deps/nix-haskell", + "type": "path" + }, + "parent": [] + }, + "nixpkgs": { + "inputs": { + "upstream": [ + "nix-haskell", + "upstream" + ] + }, + "locked": { + "allRefs": true, + "dir": "pins/nixpkgs", + "lastModified": 1794571666, + "narHash": "sha256-bisRbEDfFaS+rbt06+bMTn6U8277+fDJGLUZoF0GDKM=", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + }, + "original": { + "allRefs": true, + "dir": "pins/nixpkgs", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + } + }, + "nixpkgs-2305": { + "locked": { + "lastModified": 1705033721, + "narHash": "sha256-K5eJHmL1/kev6WuqyqqbS1cdNnSidIZ3jeqJ7GbrYnQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a1982c92d8980a0114372973cbdfe0a307f1bdea", + "type": "github" + }, + "original": { + "narHash": "sha256-K5eJHmL1/kev6WuqyqqbS1cdNnSidIZ3jeqJ7GbrYnQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a1982c92d8980a0114372973cbdfe0a307f1bdea", + "type": "github" + } + }, + "nixpkgs-2311": { + "locked": { + "lastModified": 1719957072, + "narHash": "sha256-gvFhEf5nszouwLAkT9nWsDzocUTqLWHuL++dvNjMp9I=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7144d6241f02d171d25fba3edeaf15e0f2592105", + "type": "github" + }, + "original": { + "narHash": "sha256-gvFhEf5nszouwLAkT9nWsDzocUTqLWHuL++dvNjMp9I=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7144d6241f02d171d25fba3edeaf15e0f2592105", + "type": "github" + } + }, + "nixpkgs-2405": { + "locked": { + "lastModified": 1735564410, + "narHash": "sha256-HB/FA0+1gpSs8+/boEavrGJH+Eq08/R2wWNph1sM1Dg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1e7a8f391f1a490460760065fa0630b5520f9cf8", + "type": "github" + }, + "original": { + "narHash": "sha256-HB/FA0+1gpSs8+/boEavrGJH+Eq08/R2wWNph1sM1Dg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1e7a8f391f1a490460760065fa0630b5520f9cf8", + "type": "github" + } + }, + "nixpkgs-2411": { + "locked": { + "lastModified": 1751290243, + "narHash": "sha256-kNf+obkpJZWar7HZymXZbW+Rlk3HTEIMlpc6FCNz0Ds=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5ab036a8d97cb9476fbe81b09076e6e91d15e1b6", + "type": "github" + }, + "original": { + "narHash": "sha256-kNf+obkpJZWar7HZymXZbW+Rlk3HTEIMlpc6FCNz0Ds=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5ab036a8d97cb9476fbe81b09076e6e91d15e1b6", + "type": "github" + } + }, + "nixpkgs-2505": { + "locked": { + "lastModified": 1768649915, + "narHash": "sha256-jc21hKogFnxU7KXSVTRmxC7u5D4RHwm9BAvDf5/Z1Uo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3e3f3c7f9977dc123c23ee21e8085ed63daf8c37", + "type": "github" + }, + "original": { + "narHash": "sha256-jc21hKogFnxU7KXSVTRmxC7u5D4RHwm9BAvDf5/Z1Uo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3e3f3c7f9977dc123c23ee21e8085ed63daf8c37", + "type": "github" + } + }, + "nixpkgs-2511": { + "locked": { + "lastModified": 1782904953, + "narHash": "sha256-ESJ4VgytmAt+98YLM8466luln4HyEZ9Q36b9+Bb4P5w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0921fdb3e13e40fe25fbc52b89661a9d6d32ac68", + "type": "github" + }, + "original": { + "narHash": "sha256-ESJ4VgytmAt+98YLM8466luln4HyEZ9Q36b9+Bb4P5w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0921fdb3e13e40fe25fbc52b89661a9d6d32ac68", + "type": "github" + } + }, + "nixpkgs-2605": { + "locked": { + "lastModified": 1793147889, + "narHash": "sha256-+//qXhkXCKTFoVCHAYhoEP1ZnPSx/b4IHdLI1ZMz3UU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "36173dbc6ff2b383c4d03b002fd1ea58e2e4dbcd", + "type": "github" + }, + "original": { + "narHash": "sha256-+//qXhkXCKTFoVCHAYhoEP1ZnPSx/b4IHdLI1ZMz3UU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "36173dbc6ff2b383c4d03b002fd1ea58e2e4dbcd", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1793494649, + "narHash": "sha256-Thn0OE71NF80ZfOMGCgJvKtbCcnnz0fToT/qsvb/Gtc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d357a2b54f0b6dc4aeb4e993190a52cf151b6f24", + "type": "github" + }, + "original": { + "narHash": "sha256-Thn0OE71NF80ZfOMGCgJvKtbCcnnz0fToT/qsvb/Gtc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d357a2b54f0b6dc4aeb4e993190a52cf151b6f24", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1781216227, + "narHash": "sha256-9mUW6gNwoN2SWc/l0fW4svPNOulXLl8ijqKyeSOGgJE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a0374025a863d007d98e3297f6aa46cc3141c2f0", + "type": "github" + }, + "original": { + "narHash": "sha256-9mUW6gNwoN2SWc/l0fW4svPNOulXLl8ijqKyeSOGgJE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a0374025a863d007d98e3297f6aa46cc3141c2f0", + "type": "github" + } + }, + "old-ghc-nix": { + "flake": false, + "locked": { + "lastModified": 1631092763, + "narHash": "sha256-sIKgO+z7tj4lw3u6oBZxqIhDrzSkvpHtv0Kki+lh9Fg=", + "owner": "angerman", + "repo": "old-ghc-nix", + "rev": "af48a7a7353e418119b6dfe3cd1463a657f342b8", + "type": "github" + }, + "original": { + "narHash": "sha256-sIKgO+z7tj4lw3u6oBZxqIhDrzSkvpHtv0Kki+lh9Fg=", + "owner": "angerman", + "repo": "old-ghc-nix", + "rev": "af48a7a7353e418119b6dfe3cd1463a657f342b8", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": [ + "nix-haskell", + "flake-compat" + ], + "haskell-nix": [ + "nix-haskell", + "haskell-nix" + ], + "nix-haskell": "nix-haskell", + "nixpkgs": [ + "nix-haskell", + "nixpkgs" + ], + "style.hs": "style.hs" + } + }, + "sandstone": { + "flake": false, + "locked": { + "allRefs": true, + "dir": "pins/sandstone", + "lastModified": 1794571666, + "narHash": "sha256-bisRbEDfFaS+rbt06+bMTn6U8277+fDJGLUZoF0GDKM=", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + }, + "original": { + "allRefs": true, + "dir": "pins/sandstone", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + } + }, + "stackage": { + "flake": false, + "locked": { + "lastModified": 1794024259, + "narHash": "sha256-1XjknkUH8ENHQaoWSO+M3US7/vJsEYjMgBVdci9DBmI=", + "owner": "input-output-hk", + "repo": "stackage.nix", + "rev": "2b2df46b0dbe0f415c3c69a42f922f9f2a473e91", + "type": "github" + }, + "original": { + "narHash": "sha256-1XjknkUH8ENHQaoWSO+M3US7/vJsEYjMgBVdci9DBmI=", + "owner": "input-output-hk", + "repo": "stackage.nix", + "rev": "2b2df46b0dbe0f415c3c69a42f922f9f2a473e91", + "type": "github" + } + }, + "style.hs": { + "inputs": { + "flake-compat": "flake-compat_3", + "nixpkgs": "nixpkgs_2", + "upstream": "upstream_3" + }, + "locked": { + "path": "deps/style.hs", + "type": "path" + }, + "original": { + "path": "deps/style.hs", + "type": "path" + }, + "parent": [] + }, + "upstream": { + "locked": { + "lastModified": 1794165970, + "narHash": "sha256-XuAV2cUwaod3Bt4XFVqiXz3v1w2ex16W6Sv4S7EWres=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ac588ef1c914865dad517b337ea0eb9694a4021c", + "type": "github" + }, + "original": { + "narHash": "sha256-XuAV2cUwaod3Bt4XFVqiXz3v1w2ex16W6Sv4S7EWres=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ac588ef1c914865dad517b337ea0eb9694a4021c", + "type": "github" + } + }, + "upstream_2": { + "inputs": { + "flake-compat": [ + "nix-haskell", + "flake-compat" + ], + "haskell-nix": [ + "nix-haskell", + "haskell-nix" + ], + "nixpkgs": [ + "nix-haskell", + "nixpkgs" + ], + "sandstone": [ + "nix-haskell", + "sandstone" + ] + }, + "locked": { + "allRefs": true, + "lastModified": 1794571666, + "narHash": "sha256-bisRbEDfFaS+rbt06+bMTn6U8277+fDJGLUZoF0GDKM=", + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + }, + "original": { + "allRefs": true, + "rev": "4a280fbca1d2238dc63a5935b69cdf1ae44ad28e", + "submodules": true, + "type": "git", + "url": "https://github.com/reflex-frp/nix-haskell.git" + } + }, + "upstream_3": { + "inputs": { + "flake-compat": [ + "style.hs", + "flake-compat" + ], + "nixpkgs": [ + "style.hs", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1792691575, + "narHash": "sha256-7PF0BVC728ZBxRpeGN0LnOnsUoL15TrdE6bsRG9SkUw=", + "owner": "obsidiansystems", + "repo": "style.hs", + "rev": "417c71ee50898b700221c0ef10ccc6c1befb4500", + "type": "github" + }, + "original": { + "owner": "obsidiansystems", + "repo": "style.hs", + "rev": "417c71ee50898b700221c0ef10ccc6c1befb4500", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..e1546c24 --- /dev/null +++ b/flake.nix @@ -0,0 +1,71 @@ +{ + inputs = { + self.submodules = true; + + nix-haskell.url = ./deps/nix-haskell; + "style.hs".url = ./deps/style.hs; + + nixpkgs.follows = "nix-haskell/nixpkgs"; + haskell-nix.follows = "nix-haskell/haskell-nix"; + flake-compat.follows = "nix-haskell/flake-compat"; + }; + + outputs = inputs@{ self, ... }: + let sources = import ./inputs.nix { overrides = inputs; }; + + lib = import "${sources.nixpkgs}/lib"; + + eachSystem = lib.genAttrs lib.systems.flakeExposed; + + inputsFor = system: import ./inputs.nix { + inherit system; + overrides = inputs; + }; + + projectFor = system: import ./default.nix { + inherit system; + inputs = inputsFor system; + }; + in { + legacyPackages = eachSystem (system: + projectFor system // { + # Every driver and compiler patch is meant to work for, built + # both ways. + release = import ./release.nix { + inherit system; + inputs = inputsFor system; + }; + } + ); + + packages = eachSystem (system: + let project = projectFor system; + in rec { + default = haskell-nix; + haskell-nix = project.haskell-nix.hsPkgs.patch.components.library; + nixpkgs = project.nixpkgs.packages.patch; + }); + + devShells = eachSystem (system: + let shells = import ./shell.nix { + inherit system; + inputs = inputsFor system; + }; + in shells // { default = shells.haskell-nix; } + ); + }; + + nixConfig = { + extra-substituters = [ + "https://cache.nixos.org" + "https://nixcache.reflex-frp.org" + "https://cache.iog.io" + ]; + extra-trusted-public-keys = [ + "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" + "ryantrinkle.com-1:JJiAKaRv9mWgpVAz8dwewnZe0AzzEAzPkagE9SP5NWI=" # reflex-frp + "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" + ]; + allow-import-from-derivation = "true"; + }; +} diff --git a/fourmolu.yaml b/fourmolu.yaml new file mode 100755 index 00000000..d491f16e --- /dev/null +++ b/fourmolu.yaml @@ -0,0 +1,46 @@ +#! /usr/bin/env nix +#! nix shell github:obsidiansystems/style.hs#fourmolu --command sh -c ``fourmolu --config "$1" "${@:2}"`` sh + +indentation: 2 +column-limit: none +function-arrows: leading +comma-style: leading +record-style: aligned +import-export-style: leading +indent-wheres: true +record-brace-space: true +haddock-style: single-line +haddock-style-module: single-line +let-style: inline +in-style: no-space +single-constraint-parens: never +single-deriving-parens: always +sort-constraints: false +sort-derived-classes: true +sort-deriving-clauses: true +trailing-section-operators: true +unicode: never +respectful: true + +import-grouping: + - name: "External" + rules: + - match: all + priority: 100 + - name: "Common" + rules: + - glob: Common.** + - name: "Frontend" + rules: + - glob: Frontend.** + - name: "Backend" + rules: + - glob: Backend.** + - name: "Local" + rules: + - match: local-modules + +fixities: + - infixl 1 & + - infixr 4 .~, %~ + - infixl 8 ^., ^.., ^? diff --git a/inputs.nix b/inputs.nix new file mode 100644 index 00000000..64647f72 --- /dev/null +++ b/inputs.nix @@ -0,0 +1,97 @@ +# Example: +# import ./inputs.nix { system = "x86_64-linux"; } +# => { haskell-nix = ; nixpkgs = ; sandstone = ; pkgs = ; } +# +# import ./inputs.nix { system = "x86_64-linux"; overrides = inputs; } # in flake.nix +# => the same shape, with each flake input in place of the entry of the same name +# +# import ./inputs.nix { system = "x86_64-linux"; overrides = { pkgs = myPkgs; }; } +# => the same sources, with myPkgs as pkgs +{ system ? builtins.currentSystem +, overrides ? {} +}: + +let + + # ------------------------------------------------------------------------ + # Configuration + # ------------------------------------------------------------------------ + + # Directories of thunks and git submodules. Each replaces the flake.lock entry of the same name. + thunkDirs = [ ./deps ]; + + # The package set for every consumer. + mkPkgs = sources: import sources.nixpkgs { + inherit system; + overlays = [ ]; + }; + + # ------------------------------------------------------------------------ + # Flake inputs + # ------------------------------------------------------------------------ + + src = + if builtins.pathExists ./.git + then builtins.fetchGit { url = ./.; submodules = true; } + else { outPath = ./.; }; + + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + + nodeName = ref: + if builtins.isList ref + then builtins.foldl' (name: input: nodeName lock.nodes.${name}.inputs.${input}) lock.root ref + else ref; + + flakeCompat = lock.nodes.${nodeName lock.nodes.${lock.root}.inputs.flake-compat}.locked; + + lockedInputs = + if builtins.pathExists ./flake.lock + then + (import + (fetchTarball { + url = "https://github.com/${flakeCompat.owner}/${flakeCompat.repo}/archive/${flakeCompat.rev}.tar.gz"; + sha256 = flakeCompat.narHash; + }) { inherit src; } + ).outputs.inputs + else {}; + + flakeSources = inputs: builtins.mapAttrs (_: v: v.src or v) inputs; + + # ------------------------------------------------------------------------ + # Thunks + # ------------------------------------------------------------------------ + + linkedCheckout = path: toString path + "/."; + + linkTarget = path: + if builtins.pathExists (path + "/.git") + then builtins.fetchGit { url = linkedCheckout path; submodules = true; } + else builtins.path { inherit path; }; + + thunkSource = path: + if builtins.pathExists (path + "/thunk.nix") + then import (path + "/thunk.nix") + else if builtins.readFileType path == "symlink" || builtins.pathExists (path + "/.git") + then linkTarget path + else path; + + thunkSourcesIn = dir: + let entries = builtins.readDir dir; + trees = builtins.filter + (name: builtins.elem entries.${name} [ "directory" "symlink" ]) + (builtins.attrNames entries); + entryFor = name: { + inherit name; + value = thunkSource (dir + "/${name}"); + }; + in builtins.listToAttrs (map entryFor trees); + + thunkSources = builtins.foldl' (srcs: dir: srcs // thunkSourcesIn dir) {} thunkDirs; + + # ------------------------------------------------------------------------ + # Result + # ------------------------------------------------------------------------ + + sources = flakeSources lockedInputs // thunkSources // flakeSources overrides; + +in sources // { pkgs = overrides.pkgs or (mkPkgs sources); } diff --git a/nix/deps/nix-haskell-ci/github.json b/nix/deps/nix-haskell-ci/github.json deleted file mode 100644 index a49c4d74..00000000 --- a/nix/deps/nix-haskell-ci/github.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "owner": "reflex-frp", - "repo": "nix-haskell-ci", - "branch": "main", - "private": false, - "rev": "17d1de24e89b9ca2c769d467b093d9c7fe58854e", - "sha256": "01f0dm2rjyiz6dfx8sshdyipmp6vvzx671qnvv88sk6947l0v3cr" -} diff --git a/nix/deps/nix-haskell-ci/thunk.nix b/nix/deps/nix-haskell-ci/thunk.nix deleted file mode 100644 index 20f2d28c..00000000 --- a/nix/deps/nix-haskell-ci/thunk.nix +++ /dev/null @@ -1,12 +0,0 @@ -# DO NOT HAND-EDIT THIS FILE -let fetch = { private ? false, fetchSubmodules ? false, owner, repo, rev, sha256, ... }: - if !fetchSubmodules && !private then builtins.fetchTarball { - url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; inherit sha256; - } else (import (builtins.fetchTarball { - url = "https://github.com/NixOS/nixpkgs/archive/3aad50c30c826430b0270fcf8264c8c41b005403.tar.gz"; - sha256 = "0xwqsf08sywd23x0xvw4c4ghq0l28w2ki22h0bdn766i16z9q2gr"; -}) {}).fetchFromGitHub { - inherit owner repo rev sha256 fetchSubmodules private; - }; - json = builtins.fromJSON (builtins.readFile ./github.json); -in fetch json \ No newline at end of file diff --git a/nix/deps/nixpkgs/github.json b/nix/deps/nixpkgs/github.json deleted file mode 100644 index 89cfe00a..00000000 --- a/nix/deps/nixpkgs/github.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "owner": "NixOS", - "repo": "nixpkgs", - "branch": "nixpkgs-unstable", - "private": false, - "rev": "c7eb65213bd7d95eafb8c5e2e181f04da103d054", - "sha256": "1glf6j13hbwi459qrc8kkkhfw27a08vdg17sr3zwhadg4bkxz5ia" -} diff --git a/nix/deps/nixpkgs/thunk.nix b/nix/deps/nixpkgs/thunk.nix deleted file mode 100644 index 20f2d28c..00000000 --- a/nix/deps/nixpkgs/thunk.nix +++ /dev/null @@ -1,12 +0,0 @@ -# DO NOT HAND-EDIT THIS FILE -let fetch = { private ? false, fetchSubmodules ? false, owner, repo, rev, sha256, ... }: - if !fetchSubmodules && !private then builtins.fetchTarball { - url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; inherit sha256; - } else (import (builtins.fetchTarball { - url = "https://github.com/NixOS/nixpkgs/archive/3aad50c30c826430b0270fcf8264c8c41b005403.tar.gz"; - sha256 = "0xwqsf08sywd23x0xvw4c4ghq0l28w2ki22h0bdn766i16z9q2gr"; -}) {}).fetchFromGitHub { - inherit owner repo rev sha256 fetchSubmodules private; - }; - json = builtins.fromJSON (builtins.readFile ./github.json); -in fetch json \ No newline at end of file diff --git a/nix/deps/reflex-platform/default.nix b/nix/deps/reflex-platform/default.nix deleted file mode 100644 index 2b4d4ab1..00000000 --- a/nix/deps/reflex-platform/default.nix +++ /dev/null @@ -1,2 +0,0 @@ -# DO NOT HAND-EDIT THIS FILE -import (import ./thunk.nix) \ No newline at end of file diff --git a/nix/deps/reflex-platform/github.json b/nix/deps/reflex-platform/github.json deleted file mode 100644 index d5fc383c..00000000 --- a/nix/deps/reflex-platform/github.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "owner": "reflex-frp", - "repo": "reflex-platform", - "branch": "develop", - "private": false, - "rev": "34c75631e7f2dd1409847b9df57252b96737e73a", - "sha256": "1nwyybjy65b7qnb62wcm74nqfndr8prr2xsfvaianps0yzm366d0" -} diff --git a/nix/deps/reflex-platform/thunk.nix b/nix/deps/reflex-platform/thunk.nix deleted file mode 100644 index 20f2d28c..00000000 --- a/nix/deps/reflex-platform/thunk.nix +++ /dev/null @@ -1,12 +0,0 @@ -# DO NOT HAND-EDIT THIS FILE -let fetch = { private ? false, fetchSubmodules ? false, owner, repo, rev, sha256, ... }: - if !fetchSubmodules && !private then builtins.fetchTarball { - url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; inherit sha256; - } else (import (builtins.fetchTarball { - url = "https://github.com/NixOS/nixpkgs/archive/3aad50c30c826430b0270fcf8264c8c41b005403.tar.gz"; - sha256 = "0xwqsf08sywd23x0xvw4c4ghq0l28w2ki22h0bdn766i16z9q2gr"; -}) {}).fetchFromGitHub { - inherit owner repo rev sha256 fetchSubmodules private; - }; - json = builtins.fromJSON (builtins.readFile ./github.json); -in fetch json \ No newline at end of file diff --git a/nix/project/haskell.nix b/nix/project/haskell.nix deleted file mode 100644 index ee8946c5..00000000 --- a/nix/project/haskell.nix +++ /dev/null @@ -1,8 +0,0 @@ -{ compiler ? "ghc910" }: - -{ - project = { - src = ../../.; - compiler-nix-name = compiler; - }; -} diff --git a/nix/release/haskell.nix b/nix/release/haskell.nix deleted file mode 100644 index 325d6a47..00000000 --- a/nix/release/haskell.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ haskellNix ? null }: - -let ci = import ../deps/nix-haskell-ci (if haskellNix != null then { inherit haskellNix; } else {}); - project = import ../project/haskell.nix {}; -in with ci.haskell-nix; buildMatrix { inherit project; targets = matrix.default; } diff --git a/nix/release/reflex-platform.nix b/nix/release/reflex-platform.nix deleted file mode 100644 index 64468225..00000000 --- a/nix/release/reflex-platform.nix +++ /dev/null @@ -1,66 +0,0 @@ -{ reflex-platform-fun ? import ../deps/reflex-platform -}: - -let native-reflex-platform = reflex-platform-fun { __useNewerCompiler = true; }; - inherit (native-reflex-platform.nixpkgs) lib; - systems = [ - "x86_64-linux" - # "x86_64-darwin" - ]; - - perPlatform = lib.genAttrs systems (system: let - srcFilter = - builtins.filterSource (path: type: !(builtins.elem (baseNameOf path) [ - "release.nix" - ".git" - "dist" - "dist-newstyle" - "cabal.haskell-ci" - "cabal.project" - ".travis.yml" - ])); - reflex-platform = reflex-platform-fun { inherit system; __useNewerCompiler = true; }; - compilers = [ - "ghc" - "ghcjs" - ] ++ lib.optionals (reflex-platform.androidSupport) [ - "ghcAndroidAarch64" - "ghcAndroidAarch32" - ] ++ lib.optionals (reflex-platform.iosSupport) [ - "ghcIosAarch64" - ]; - nixpkgsGhcs = - let - pkgs = import ../deps/nixpkgs { inherit system; }; - nixGhc945 = pkgs.haskell.packages.ghc945.override { - }; - nixGhc961 = pkgs.haskell.packages.ghc961.override { - }; - in - { - ghc945 = nixGhc945.callCabal2nix "patch" srcFilter {}; - ghc961 = nixGhc961.callCabal2nix "patch" srcFilter {}; - }; - compilerPkgs = lib.genAttrs compilers (ghc: let - reflex-platform = reflex-platform-fun { - inherit system; - __useNewerCompiler = true; - haskellOverlays = [ - # Use this package's source for reflex - (self: super: { - _dep = super._dep // { - patch = srcFilter ../../.; - }; - }) - ]; - }; - in reflex-platform.${ghc}.patch); - in compilerPkgs // nixpkgsGhcs // { - cache = reflex-platform.pinBuildInputs "patch-${system}" - (builtins.attrValues compilerPkgs); - }); - - metaCache = native-reflex-platform.pinBuildInputs "patch-everywhere" - (map (a: a.cache) (builtins.attrValues perPlatform)); - -in perPlatform // { inherit metaCache; } diff --git a/nix/shell/haskell.nix b/nix/shell/haskell.nix deleted file mode 100644 index e0e2d76f..00000000 --- a/nix/shell/haskell.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ haskellNix ? null }: - -let ci = import ../deps/nix-haskell-ci (if haskellNix != null then { inherit haskellNix; } else {}); - haskell = ci.nix-haskell; - project = import ../project/haskell.nix {}; -in haskell.project project diff --git a/nix/shell/reflex-platform.nix b/nix/shell/reflex-platform.nix deleted file mode 100644 index 426976a6..00000000 --- a/nix/shell/reflex-platform.nix +++ /dev/null @@ -1,15 +0,0 @@ -let - rp = import ../deps/reflex-platform { __useNewerCompiler = true; }; - pkgs = rp.nixpkgs; - system = builtins.currentSystem; -in - pkgs.mkShell { - name = "shell"; - buildInputs = [ - pkgs.cabal-install - pkgs.ghcid - ]; - inputsFrom = [ - (import ../release/reflex-platform.nix {}).${system}.ghc.env - ]; - } diff --git a/patch.cabal b/patch.cabal index 811fd205..4eb157c9 100644 --- a/patch.cabal +++ b/patch.cabal @@ -1,14 +1,14 @@ -cabal-version: >=1.10 +cabal-version: 2.2 name: patch -version: 0.0.8.4 -license: BSD3 +version: 0.0.9.0 +license: BSD-3-Clause license-file: LICENSE maintainer: maintainer@obsidian.systems author: Ryan Trinkle stability: Experimental tested-with: - ghc ==8.4.4 || ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.1 || ==9.2.5 || ==9.4.5 || ==9.6.1 || ==9.8.2 || ==9.10.1 || ==9.12.1 || ==9.14.1 - ghcjs ==8.6 || ==8.10 + ghc ==8.10.7 || ==9.0.1 || ==9.2.5 || ==9.4.5 || ==9.6.1 || ==9.8.2 || ==9.10.1 || ==9.12.1 || ==9.14.1 + ghcjs ==8.10 homepage: https://obsidian.systems bug-reports: https://github.com/reflex-frp/patch/issues @@ -38,7 +38,78 @@ flag split-these flag hlint description: Enable hlint test +flag strict + description: + Build with options, such as -Werror, which are inconvenient for development but good for CI + + default: False + manual: True + +common common + default-extensions: + AllowAmbiguousTypes + BangPatterns + ConstraintKinds + DataKinds + DefaultSignatures + DeriveDataTypeable + DeriveFunctor + DeriveGeneric + DeriveTraversable + DerivingStrategies + EmptyCase + EmptyDataDecls + ExistentialQuantification + FlexibleContexts + FlexibleInstances + FunctionalDependencies + GADTs + GeneralizedNewtypeDeriving + ImportQualifiedPost + LambdaCase + MultiParamTypeClasses + NoMonomorphismRestriction + OverloadedStrings + PatternGuards + PatternSynonyms + PolyKinds + RankNTypes + RecordWildCards + RecursiveDo + ScopedTypeVariables + StandaloneDeriving + TemplateHaskell + TupleSections + TypeApplications + TypeFamilies + TypeOperators + UndecidableSuperClasses + ViewPatterns + + if flag(strict) + ghc-options: -Werror + + ghc-options: + -O2 -fexpose-all-unfoldings -fspecialise -fspecialise-aggressively + -flate-specialise -fcross-module-specialise + + if !arch(wasm32) + ghc-options: -threaded -rtsopts -with-rtsopts=-N + + ghc-options: + -Wall -fno-show-valid-hole-fits -Wno-type-defaults + -Wno-partial-type-signatures -Wincomplete-record-updates + -Werror=incomplete-record-updates -Wincomplete-patterns + -Werror=incomplete-patterns -Wincomplete-uni-patterns + -Werror=incomplete-uni-patterns -Wpartial-fields + -Werror=partial-fields -Wmissing-fields -Werror=missing-fields + -Widentities -Wredundant-constraints -Wunused-packages + + ghc-options: + -Wmissing-deriving-strategies -Werror=missing-deriving-strategies + library + import: common exposed-modules: Data.Functor.Misc Data.Monoid.DecidablyEmpty @@ -55,23 +126,16 @@ library hs-source-dirs: src default-language: Haskell2010 - default-extensions: PolyKinds - ghc-options: -Wall -fwarn-redundant-constraints -fwarn-tabs build-depends: - base >=4.9 && <=4.23, + base >=4.14 && <=4.23, constraints-extras >=0.3 && <0.5, commutative-semigroups >=0.0 && <0.3, - containers >=0.6 && <0.8, + containers >=0.6 && <0.9, dependent-map >=0.3 && <0.5, dependent-sum >=0.6 && <0.8, lens >=4.7 && <5.4, indexed-traversable >=0.1 && <0.2, - semigroupoids >=4.0 && <7, - transformers >=0.5.6.0 && <0.7, - witherable >=0.3 && <0.6 - - if impl(ghc <8.6) - build-depends: base-orphans >=0.8 && <0.10 + transformers >=0.5.6.0 && <0.7 if flag(split-these) build-depends: @@ -85,6 +149,7 @@ library monoidal-containers ==0.4.0.0 test-suite tests + import: common type: exitcode-stdio-1.0 main-is: tests.hs hs-source-dirs: test @@ -100,6 +165,7 @@ test-suite tests buildable: False test-suite hlint + import: common type: exitcode-stdio-1.0 main-is: hlint.hs hs-source-dirs: test @@ -118,7 +184,7 @@ test-suite hlint build-depends: hlint (<2.1 || >=2.2.2) && <3.5 else - build-depends: hlint >=3.5 && <3.6 + build-depends: hlint >=3.5 && <3.11 if ((impl(ghcjs >=0) || arch(javascript)) || !flag(hlint)) buildable: False diff --git a/project.nix b/project.nix new file mode 100644 index 00000000..d305b0c5 --- /dev/null +++ b/project.nix @@ -0,0 +1,26 @@ +{ config, lib, ... }: + +{ + name = "patch"; + src = ./.; + + haskell-nix = { + options.shell.withHaddock = false; + }; + + nixpkgs = { + # Where this driver builds against a compiler newer than the bounds its + # package set was written for, the bounds are the problem. Reading + # cabal.project through cabal brings `exact-configuration` with it. Cabal + # is then told every dependency and reads no bound. For a driver with no + # solver, that amounts to `allow-newer: *:*`. + options.use-plan = + lib.versionAtLeast config.nixpkgs.compiler-version "9.14"; + }; + + shell = { + packages = ps: with ps; [ patch ]; + withHoogle = false; + }; + +} diff --git a/release.nix b/release.nix index 1ec7dcc2..86f994b1 100644 --- a/release.nix +++ b/release.nix @@ -1,11 +1,141 @@ -{ pkgs ? import {} }: +# Every combination of driver and compiler patch is meant to work for. Each +# is built two ways: as the drivers build it, and as a person would inside +# the project's shell. `checks` is the style checks. +# +# nix-build release.nix -A all +# nix-build release.nix -A build +# nix-build release.nix -A build.haskell-nix.ghc914 +# nix-build release.nix -A shell-build.nixpkgs.ghc912 +# nix-build release.nix -A checks +# nix-instantiate --eval --strict --json release.nix -A attr-paths +# +# The nixpkgs driver has no 9.14 package set worth building against, so it +# builds only 9.12. +{ system ? builtins.currentSystem +, inputs ? import ./inputs.nix { inherit system; } +}: -let reflex-platform-release = import ./nix/release/reflex-platform.nix {}; - haskell-nix-release = import ./nix/release/haskell.nix {}; +let nix-haskell = import inputs.nix-haskell { inherit system inputs; }; -in pkgs.runCommand "release" {} '' - mkdir -p $out + variant = modules: nix-haskell ([ (import ./project.nix) ] ++ modules); - ln -s ${reflex-platform-release.metaCache} $out/reflex-platform - ln -s ${haskell-nix-release} $out/haskell-nix -'' + stock = variant []; + + lib = stock.pkgs.lib; + +in with (import (inputs.nix-haskell + "/libs/prelude") { inherit lib; }); + +let + # The one matrix of driver and compiler series. A cell is a project, the + # driver that builds it, and the path it takes in every result set. + cells = [ + + { path = [ "haskell-nix" "ghc912" ]; project = seriesProject "9.12" []; driver = "haskell-nix"; } + { path = [ "haskell-nix" "ghc914" ]; project = seriesProject "9.14" []; driver = "haskell-nix"; } + { path = [ "nixpkgs" "ghc912" ]; project = seriesProject "9.12" []; driver = "nixpkgs"; } + + ]; + + seriesProject = series: modules: + variant ([ { compiler.name = ghcName series; } strict ] ++ modules); + + ghcName = series: "ghc${lib.replaceStrings [ "." ] [ "" ] series}"; + + # The tree of one result set: each cell's derivations at the cell's + # path, every level marked for `nix-build`. + matrix = leaf: + let subtrees = map (cell: lib.setAttrByPath cell.path (leaf cell)) cells; + in recurse-for-derivations (lib.foldl lib.recursiveUpdate {} subtrees); + + # Each result set: what a cell builds. + resultSets = { + build = built; + shell-build = shellBuild; + }; + + # patch's library, as one driver builds it. + built = cell: + lib.genAttrs libraries (driverLibrary.${cell.driver} cell.project.${cell.driver}.project); + + # haskell.nix gives a package a tree of components, the nixpkgs driver one + # derivation. + driverLibrary = { + haskell-nix = proj: name: proj.hsPkgs.${name}.components.library; + nixpkgs = proj: name: proj.packages.${name}; + }; + + # The build a person would run, in the shell they would run it in. cabal + # needs no package index: the shell's package database already carries + # everything the project depends on. A configuration naming no + # repository keeps cabal from fetching one it cannot reach. + # One `buildCommand` rather than phases: the nixpkgs driver's shell states + # its own, which stands in for the whole phase list, so a phase written + # here would never run in that shell. + shellBuild = cell: + cell.project.${cell.driver}.project.shell.overrideAttrs (old: { + name = "patch-${cell.driver}-shell-build"; + + buildCommand = '' + # What entering the shell runs. + eval "$shellHook" + + cp -r ${cell.project.config.src-cleaned} source + chmod -R u+w source + cd source + + export HOME=$TMPDIR + export CABAL_CONFIG=$TMPDIR/cabal.config + echo 'jobs: $ncpus' > $CABAL_CONFIG + echo 'active-repositories: :none' >> cabal.project.local + echo 'tests: False' >> cabal.project.local + echo 'benchmarks: False' >> cabal.project.local + + cabal build --offline lib:patch + touch $out + ''; + }); + + # The name `nix-build -A` takes for a path through the tree. + dotted = path: lib.concatStringsSep "." path; + + # The names of every entry of one result set, under the set's name. + setEntries = name: + map (cell: dotted ([ name ] ++ cell.path)) cells; + + released = lib.mapAttrs (_: matrix) resultSets // { + checks = recurse-for-derivations checks; + }; + + checks = { + fourmolu = style.fourmolu-check; + hlint = style.hlint-check; + }; + + style = import ./style.nix { inherit system inputs; pkgs = stock.pkgs; }; + + strict = { + packages = lib.genAttrs libraries (_: { flags.strict = true; }); + }; + + libraries = [ "patch" ]; + +in released // { + + all = stock.pkgs.linkFarm "patch-release" + (link-farm-entries "" released); + + # Every derivation here, named the way `nix-build -A` takes it, for a CI + # matrix that builds each on its own runner. + # + # Example: + # + # attr-paths + # => [ "build.haskell-nix.ghc912" + # ... + # "shell-build.nixpkgs.ghc912" + # "checks.fourmolu" + # "checks.hlint" ] + attr-paths = lib.concatMap setEntries (lib.attrNames resultSets) + ++ map (name: "checks.${name}") (lib.attrNames checks); + +} diff --git a/shell.nix b/shell.nix index 234896ac..0e7bac4f 100644 --- a/shell.nix +++ b/shell.nix @@ -1,9 +1,21 @@ -{ pkgs ? import {} }: +{ system ? builtins.currentSystem +, inputs ? import ./inputs.nix { inherit system; } +, pkgs ? inputs.pkgs +}: -let reflex-platform-shell = import ./nix/shell/reflex-platform.nix; - haskell-nix-shell = import ./nix/shell/haskell.nix {}; +let project = import ./default.nix { inherit system inputs; }; + style = import ./style.nix { inherit system inputs pkgs; }; + + withStyle = shell: pkgs.mkShell { + inputsFrom = [ shell ]; + packages = [ + style.fourmolu + style.hlint + ]; + shellHook = style.syncConfigs "$PWD"; + }; in { - inherit reflex-platform-shell; - inherit haskell-nix-shell; + haskell-nix = withStyle project.haskell-nix.shell; + nixpkgs = withStyle project.nixpkgs.shell; } diff --git a/src/Data/Functor/Misc.hs b/src/Data/Functor/Misc.hs index 8653369b..26f32141 100644 --- a/src/Data/Functor/Misc.hs +++ b/src/Data/Functor/Misc.hs @@ -1,23 +1,11 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE DeriveDataTypeable #-} -{-# LANGUAGE DeriveFunctor #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE PolyKinds #-} -{-# LANGUAGE RankNTypes #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE StandaloneDeriving #-} - -{- | -Description: Misc utilities relating to functor. - -This module provides types and functions with no particular theme, but which -are relevant to the use of 'Functor'-based datastructures like -'Data.Dependent.Map.DMap'. --} + +-- | +-- Description: Misc utilities relating to functor. +-- +-- This module provides types and functions with no particular theme, but which +-- are relevant to the use of 'Functor'-based datastructures like +-- 'Data.Dependent.Map.DMap'. module Data.Functor.Misc ( -- * Const2 Const2 (..) @@ -27,8 +15,10 @@ module Data.Functor.Misc , dmapToMapWith , mapToDMap , weakenDMapWith + -- * WrapArg , WrapArg (..) + -- * Convenience functions for DMap , mapWithFunctorToDMap , intMapWithFunctorToDMap @@ -42,19 +32,19 @@ module Data.Functor.Misc ) where import Data.Dependent.Map (DMap) -import qualified Data.Dependent.Map as DMap +import Data.Dependent.Map qualified as DMap import Data.Dependent.Sum import Data.Functor.Identity import Data.GADT.Compare import Data.GADT.Show import Data.IntMap (IntMap) -import qualified Data.IntMap as IntMap +import Data.IntMap qualified as IntMap import Data.Kind (Type) import Data.Map (Map) -import qualified Data.Map as Map +import Data.Map qualified as Map import Data.Some (Some, mkSome) import Data.These -import Data.Type.Equality ((:~:)(Refl)) +import Data.Type.Equality ((:~:) (Refl)) -------------------------------------------------------------------------------- -- Const2 @@ -70,10 +60,10 @@ data Const2 :: Type -> x -> x -> Type where unConst2 :: Const2 k v v' -> k unConst2 (Const2 k) = k -deriving instance Eq k => Eq (Const2 k v v') -deriving instance Ord k => Ord (Const2 k v v') -deriving instance Show k => Show (Const2 k v v') -deriving instance Read k => Read (Const2 k v v) +deriving stock instance Eq k => Eq (Const2 k v v') +deriving stock instance Ord k => Ord (Const2 k v v') +deriving stock instance Show k => Show (Const2 k v v') +deriving stock instance Read k => Read (Const2 k v v) instance Show k => GShow (Const2 k v) where gshowsPrec n x@(Const2 _) = showsPrec n x @@ -81,8 +71,8 @@ instance Show k => GShow (Const2 k v) where instance Eq k => GEq (Const2 k v) where geq (Const2 a) (Const2 b) = if a == b - then Just Refl - else Nothing + then Just Refl + else Nothing instance Ord k => GCompare (Const2 k v) where gcompare (Const2 a) (Const2 b) = case compare a b of @@ -92,35 +82,35 @@ instance Ord k => GCompare (Const2 k v) where -- | Convert a 'DMap' to a regular 'Map' dmapToMap :: DMap (Const2 k v) Identity -> Map k v -dmapToMap = Map.fromDistinctAscList . map (\(Const2 k :=> Identity v) -> (k, v)) . DMap.toAscList +dmapToMap = Map.fromDistinctAscList . fmap (\(Const2 k :=> Identity v) -> (k, v)) . DMap.toAscList -- | Convert a 'DMap' to an 'IntMap' dmapToIntMap :: DMap (Const2 IntMap.Key v) Identity -> IntMap v -dmapToIntMap = IntMap.fromDistinctAscList . map (\(Const2 k :=> Identity v) -> (k, v)) . DMap.toAscList +dmapToIntMap = IntMap.fromDistinctAscList . fmap (\(Const2 k :=> Identity v) -> (k, v)) . DMap.toAscList -- | Convert a 'DMap' to a regular 'Map', applying the given function to remove -- the wrapping 'Functor' dmapToMapWith :: (f v -> v') -> DMap (Const2 k v) f -> Map k v' -dmapToMapWith f = Map.fromDistinctAscList . map (\(Const2 k :=> v) -> (k, f v)) . DMap.toAscList +dmapToMapWith f = Map.fromDistinctAscList . fmap (\(Const2 k :=> v) -> (k, f v)) . DMap.toAscList -- | Convert a regular 'Map' to a 'DMap' mapToDMap :: Map k v -> DMap (Const2 k v) Identity -mapToDMap = DMap.fromDistinctAscList . map (\(k, v) -> Const2 k :=> Identity v) . Map.toAscList +mapToDMap = DMap.fromDistinctAscList . fmap (\(k, v) -> Const2 k :=> Identity v) . Map.toAscList -- | Convert a regular 'Map', where the values are already wrapped in a functor, -- to a 'DMap' mapWithFunctorToDMap :: Map k (f v) -> DMap (Const2 k v) f -mapWithFunctorToDMap = DMap.fromDistinctAscList . map (\(k, v) -> Const2 k :=> v) . Map.toAscList +mapWithFunctorToDMap = DMap.fromDistinctAscList . fmap (\(k, v) -> Const2 k :=> v) . Map.toAscList -- | Convert a regular 'IntMap', where the values are already wrapped in a -- functor, to a 'DMap' intMapWithFunctorToDMap :: IntMap (f v) -> DMap (Const2 IntMap.Key v) f -intMapWithFunctorToDMap = DMap.fromDistinctAscList . map (\(k, v) -> Const2 k :=> v) . IntMap.toAscList +intMapWithFunctorToDMap = DMap.fromDistinctAscList . fmap (\(k, v) -> Const2 k :=> v) . IntMap.toAscList -- | Convert a 'DMap' to a regular 'Map' by forgetting the types associated with -- the keys, using a function to remove the wrapping 'Functor' weakenDMapWith :: (forall a. v a -> v') -> DMap k v -> Map (Some k) v' -weakenDMapWith f = Map.fromDistinctAscList . map (\(k :=> v) -> (mkSome k, f v)) . DMap.toAscList +weakenDMapWith f = Map.fromDistinctAscList . fmap (\(k :=> v) -> (mkSome k, f v)) . DMap.toAscList -------------------------------------------------------------------------------- -- WrapArg @@ -132,10 +122,10 @@ weakenDMapWith f = Map.fromDistinctAscList . map (\(k :=> v) -> (mkSome k, f v)) data WrapArg :: (k -> Type) -> (k -> Type) -> Type -> Type where WrapArg :: f a -> WrapArg g f (g a) -deriving instance Eq (f a) => Eq (WrapArg g f (g' a)) -deriving instance Ord (f a) => Ord (WrapArg g f (g' a)) -deriving instance Show (f a) => Show (WrapArg g f (g' a)) -deriving instance Read (f a) => Read (WrapArg g f (g a)) +deriving stock instance Eq (f a) => Eq (WrapArg g f (g' a)) +deriving stock instance Ord (f a) => Ord (WrapArg g f (g' a)) +deriving stock instance Show (f a) => Show (WrapArg g f (g' a)) +deriving stock instance Read (f a) => Read (WrapArg g f (g a)) instance GEq f => GEq (WrapArg g f) where geq (WrapArg a) (WrapArg b) = (\Refl -> Refl) <$> geq a b @@ -154,25 +144,28 @@ instance GCompare f => GCompare (WrapArg g f) where -- well as the value. The provided function MUST preserve the ordering of the -- keys, or the resulting 'DMap' will be malformed. mapKeyValuePairsMonotonic :: (DSum k v -> DSum k' v') -> DMap k v -> DMap k' v' -mapKeyValuePairsMonotonic f = DMap.fromDistinctAscList . map f . DMap.toAscList +mapKeyValuePairsMonotonic f = DMap.fromDistinctAscList . fmap f . DMap.toAscList {-# INLINE combineDMapsWithKey #-} + -- | Union two 'DMap's of different types, yielding another type. Each key that -- is present in either input map will be present in the output. -combineDMapsWithKey :: forall f g h i. - GCompare f - => (forall a. f a -> These (g a) (h a) -> i a) - -> DMap f g - -> DMap f h - -> DMap f i +combineDMapsWithKey + :: forall f g h i + . GCompare f + => (forall a. f a -> These (g a) (h a) -> i a) + -> DMap f g + -> DMap f h + -> DMap f i combineDMapsWithKey f mg mh = DMap.fromList $ go (DMap.toList mg) (DMap.toList mh) - where go :: [DSum f g] -> [DSum f h] -> [DSum f i] - go [] hs = map (\(hk :=> hv) -> hk :=> f hk (That hv)) hs - go gs [] = map (\(gk :=> gv) -> gk :=> f gk (This gv)) gs - go gs@((gk :=> gv) : gs') hs@((hk :=> hv) : hs') = case gk `gcompare` hk of - GLT -> (gk :=> f gk (This gv)) : go gs' hs - GEQ -> (gk :=> f gk (These gv hv)) : go gs' hs' - GGT -> (hk :=> f hk (That hv)) : go gs hs' + where + go :: [DSum f g] -> [DSum f h] -> [DSum f i] + go [] hs = fmap (\(hk :=> hv) -> hk :=> f hk (That hv)) hs + go gs [] = fmap (\(gk :=> gv) -> gk :=> f gk (This gv)) gs + go gs@((gk :=> gv) : gs') hs@((hk :=> hv) : hs') = case gk `gcompare` hk of + GLT -> (gk :=> f gk (This gv)) : go gs' hs + GEQ -> (gk :=> f gk (These gv hv)) : go gs' hs' + GGT -> (hk :=> f hk (That hv)) : go gs hs' -- | Extract the values of a 'DMap' of 'EitherTag's. dmapToThese :: DMap (EitherTag a b) Identity -> Maybe (These a b) @@ -187,9 +180,9 @@ data EitherTag l r a where LeftTag :: EitherTag l r l RightTag :: EitherTag l r r -deriving instance Show (EitherTag l r a) -deriving instance Eq (EitherTag l r a) -deriving instance Ord (EitherTag l r a) +deriving stock instance Show (EitherTag l r a) +deriving stock instance Eq (EitherTag l r a) +deriving stock instance Ord (EitherTag l r a) instance GEq (EitherTag l r) where geq a b = case (a, b) of @@ -212,8 +205,8 @@ instance GShow (EitherTag l r) where -- | Convert 'Either' to a 'DSum'. Inverse of 'dsumToEither'. eitherToDSum :: Either a b -> DSum (EitherTag a b) Identity eitherToDSum = \case - Left a -> (LeftTag :=> Identity a) - Right b -> (RightTag :=> Identity b) + Left a -> LeftTag :=> Identity a + Right b -> RightTag :=> Identity b -- | Convert 'DSum' to 'Either'. Inverse of 'eitherToDSum'. dsumToEither :: DSum (EitherTag a b) Identity -> Either a b @@ -229,7 +222,9 @@ dsumToEither = \case -- because that would make the @f@ parameter have a nominal type role. -- We need @f@ to be representational so that we can use safe -- @'Data.Coerce.coerce'@. -newtype ComposeMaybe f a = - ComposeMaybe { getComposeMaybe :: Maybe (f a) } deriving (Show, Eq, Ord) +newtype ComposeMaybe f a + = ComposeMaybe {getComposeMaybe :: Maybe (f a)} + deriving stock (Show) + deriving newtype (Eq, Ord) -deriving instance Functor f => Functor (ComposeMaybe f) +deriving stock instance Functor f => Functor (ComposeMaybe f) diff --git a/src/Data/Monoid/DecidablyEmpty.hs b/src/Data/Monoid/DecidablyEmpty.hs index e0072536..5c6bbfee 100644 --- a/src/Data/Monoid/DecidablyEmpty.hs +++ b/src/Data/Monoid/DecidablyEmpty.hs @@ -1,36 +1,26 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE DefaultSignatures #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# LANGUAGE TypeOperators #-} -- TODO upstream somwhere else? -{-| -Description: This module provides a class to decide whether a monoid element is the identity. --} + +-- | +-- Description: This module provides a class to decide whether a monoid element is the identity. module Data.Monoid.DecidablyEmpty where -import Data.Functor.Identity +import Data.Dependent.Map qualified as DMap import Data.Functor.Const -import Data.Monoid +import Data.Functor.Identity +import Data.GADT.Compare +import Data.IntMap qualified as IntMap +import Data.IntSet qualified as IntSet +import Data.Map qualified as Map import Data.Maybe (isNothing) -#if MIN_VERSION_base(4,11,0) +import Data.Monoid import Data.Ord -#endif import Data.Proxy import Data.Semigroup hiding (First, Last) -#if MIN_VERSION_base(4,12,0) +import Data.Sequence qualified as Seq +import Data.Set qualified as Set import GHC.Generics -#endif - -import qualified Data.IntSet as IntSet -import qualified Data.IntMap as IntMap -import qualified Data.Map as Map -import qualified Data.Sequence as Seq -import qualified Data.Set as Set - -import Data.GADT.Compare -import qualified Data.Dependent.Map as DMap -- | A 'DecidablyEmpty' is one where it can be computed whether or not an -- arbitrary value is 'mempty'. @@ -49,50 +39,41 @@ instance DecidablyEmpty Ordering instance DecidablyEmpty () instance DecidablyEmpty Any instance DecidablyEmpty All + -- instance DecidablyEmpty Lifetime -- instance DecidablyEmpty Event instance DecidablyEmpty [a] where isEmpty = null -instance -#if MIN_VERSION_base(4,11,0) - Semigroup a -#else - Monoid a -#endif - => DecidablyEmpty (Maybe a) where +instance Semigroup a => DecidablyEmpty (Maybe a) where isEmpty = isNothing instance (Num a, Eq a) => DecidablyEmpty (Product a) where isEmpty = (== 1) instance (Num a, Eq a) => DecidablyEmpty (Sum a) where isEmpty = (== 0) -deriving instance DecidablyEmpty a => DecidablyEmpty (Dual a) +deriving newtype instance DecidablyEmpty a => DecidablyEmpty (Dual a) instance DecidablyEmpty (First a) where isEmpty (First a) = isNothing a instance DecidablyEmpty (Last a) where isEmpty (Last a) = isNothing a -deriving instance DecidablyEmpty a => DecidablyEmpty (Identity a) +deriving newtype instance DecidablyEmpty a => DecidablyEmpty (Identity a) #if !MIN_VERSION_base(4,16,0) instance Semigroup a => DecidablyEmpty (Option a) where isEmpty (Option a) = isNothing a #endif -deriving instance DecidablyEmpty m => DecidablyEmpty (WrappedMonoid m) +deriving newtype instance DecidablyEmpty m => DecidablyEmpty (WrappedMonoid m) instance (Ord a, Bounded a) => DecidablyEmpty (Max a) instance (Ord a, Bounded a) => DecidablyEmpty (Min a) instance DecidablyEmpty (Proxy s) -deriving instance DecidablyEmpty a => DecidablyEmpty (Const a b) -#if MIN_VERSION_base(4,11,0) -deriving instance DecidablyEmpty a => DecidablyEmpty (Down a) -#endif -#if MIN_VERSION_base(4,12,0) -deriving instance DecidablyEmpty p => DecidablyEmpty (Par1 p) +deriving newtype instance DecidablyEmpty a => DecidablyEmpty (Const a b) +deriving newtype instance DecidablyEmpty a => DecidablyEmpty (Down a) +deriving newtype instance DecidablyEmpty p => DecidablyEmpty (Par1 p) instance DecidablyEmpty (U1 p) -deriving instance DecidablyEmpty (f p) => DecidablyEmpty (Rec1 f p) -deriving instance DecidablyEmpty (f p) => DecidablyEmpty (M1 i c f p) -deriving instance DecidablyEmpty c => DecidablyEmpty (K1 i c p) +deriving newtype instance DecidablyEmpty (f p) => DecidablyEmpty (Rec1 f p) +deriving newtype instance DecidablyEmpty (f p) => DecidablyEmpty (M1 i c f p) +deriving newtype instance DecidablyEmpty c => DecidablyEmpty (K1 i c p) instance (DecidablyEmpty (f p), DecidablyEmpty (g p)) => DecidablyEmpty ((f :*: g) p) where isEmpty (x :*: y) = isEmpty x && isEmpty y -deriving instance DecidablyEmpty (f (g p)) => DecidablyEmpty ((f :.: g) p) -#endif +deriving newtype instance DecidablyEmpty (f (g p)) => DecidablyEmpty ((f :.: g) p) instance (DecidablyEmpty a, DecidablyEmpty b) => DecidablyEmpty (a, b) where isEmpty (a, b) = isEmpty a && isEmpty b diff --git a/src/Data/Patch.hs b/src/Data/Patch.hs index 772d2a90..ba4f931d 100644 --- a/src/Data/Patch.hs +++ b/src/Data/Patch.hs @@ -1,51 +1,49 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE TypeOperators #-} - -{-| -Description: - This module defines the 'Group' class, and reexports the other modules. --} +{-# OPTIONS_GHC -Wno-deprecations #-} + +-- | +-- Description: +-- This module defines the 'Group' class, and reexports the other modules. module Data.Patch ( module Data.Patch , module X ) where -import Data.Semigroup.Commutative import Data.Functor.Const (Const (..)) import Data.Functor.Identity import Data.Map.Monoidal (MonoidalMap) import Data.Proxy +import Data.Semigroup.Commutative import GHC.Generics #if !MIN_VERSION_base(4,18,0) import Control.Applicative (liftA2) #endif -#if !MIN_VERSION_base(4,11,0) -import Data.Semigroup (Semigroup (..)) -#endif - --- N.B. Intentionally reexporting `Additive`, the deprecated alias, as --- this is a reexport for backwards compatibility. -import Data.Semigroup.Additive as X import Data.Patch.Class as X import Data.Patch.DMap as X hiding (getDeletions) import Data.Patch.DMapWithMove as X - ( PatchDMapWithMove, const2PatchDMapWithMoveWith, mapPatchDMapWithMove + ( PatchDMapWithMove + , const2PatchDMapWithMoveWith + , mapPatchDMapWithMove , patchDMapWithMoveToPatchMapWithMoveWith - , traversePatchDMapWithMoveWithKey, unPatchDMapWithMove - , unsafePatchDMapWithMove, weakenPatchDMapWithMoveWith + , traversePatchDMapWithMoveWithKey + , unPatchDMapWithMove + , unsafePatchDMapWithMove + , weakenPatchDMapWithMoveWith ) import Data.Patch.IntMap as X hiding (getDeletions) import Data.Patch.Map as X import Data.Patch.MapWithMove as X - ( PatchMapWithMove, patchMapWithMoveNewElements - , patchMapWithMoveNewElementsMap, unPatchMapWithMove + ( PatchMapWithMove + , patchMapWithMoveNewElements + , patchMapWithMoveNewElementsMap + , unPatchMapWithMove , unsafePatchMapWithMove ) +-- N.B. Intentionally reexporting `Additive`, the deprecated alias, as +-- this is a reexport for backwards compatibility. +import Data.Semigroup.Additive as X -- | A 'Group' is a 'Monoid' where every element has an inverse. class (Semigroup q, Monoid q) => Group q where @@ -54,7 +52,7 @@ class (Semigroup q, Monoid q) => Group q where r ~~ s = r <> negateG s -- | The elements of an 'Commutative' 'Semigroup' can be considered as patches of their own type. -newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p } +newtype AdditivePatch p = AdditivePatch {unAdditivePatch :: p} instance Commutative p => Patch (AdditivePatch p) where type PatchTarget (AdditivePatch p) = p @@ -91,10 +89,10 @@ instance Group (Proxy x) where _ ~~ _ = Proxy -- | Const lifts groups into a functor. -deriving instance Group a => Group (Const a x) +deriving newtype instance Group a => Group (Const a x) -- | Identity lifts groups pointwise (at only one point) -deriving instance Group a => Group (Identity a) +deriving newtype instance Group a => Group (Identity a) -- | Functions lift groups pointwise. instance Group b => Group (a -> b) where diff --git a/src/Data/Patch/Class.hs b/src/Data/Patch/Class.hs index 6bfb03a0..36ad7636 100644 --- a/src/Data/Patch/Class.hs +++ b/src/Data/Patch/Class.hs @@ -1,25 +1,19 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeFamilies #-} -{-| -Description: The module provides the 'Patch' class. - -This is a class for types which represent changes made to other types --} +-- | +-- Description: The module provides the 'Patch' class. +-- +-- This is a class for types which represent changes made to other types module Data.Patch.Class where import Data.Functor.Identity import Data.Kind (Type) import Data.Maybe +import Data.Proxy import Data.Semigroup - ( Sum (..) - , Product (..) -#if !MIN_VERSION_base(4,11,0) - , Semigroup(..) -#endif + ( Product (..) + , Sum (..) ) -import Data.Proxy -- | A 'Patch' type represents a kind of change made to a datastructure. -- @@ -27,6 +21,7 @@ import Data.Proxy -- the law that @applyAlways (f <> g) == applyAlways f . applyAlways g@. class Patch p where type PatchTarget p :: Type + -- | Apply the patch @p a@ to the value @a@. If no change is needed, return -- 'Nothing'. apply :: p -> PatchTarget p -> Maybe (PatchTarget p) diff --git a/src/Data/Patch/DMap.hs b/src/Data/Patch/DMap.hs index 7d12ad55..c61ca5a1 100644 --- a/src/Data/Patch/DMap.hs +++ b/src/Data/Patch/DMap.hs @@ -1,46 +1,35 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE PolyKinds #-} -{-# LANGUAGE Rank2Types #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# LANGUAGE TypeFamilies #-} - -{-| -Description: A basic 'Patch' on 'DMap' - -Patches of this type consist only of insertions (including overwrites) and -deletions. --} -module Data.Patch.DMap where -import Data.Patch.Class -import Data.Patch.IntMap -import Data.Patch.Map +-- | +-- Description: A basic 'Patch' on 'DMap' +-- +-- Patches of this type consist only of insertions (including overwrites) and +-- deletions. +module Data.Patch.DMap where import Data.Dependent.Map (DMap) +import Data.Dependent.Map qualified as DMap import Data.Dependent.Sum (DSum (..)) -import Data.GADT.Compare (GCompare (..)) -import qualified Data.Dependent.Map as DMap import Data.Functor.Constant +import Data.GADT.Compare (GCompare (..)) +import Data.IntMap qualified as IntMap +import Data.Map qualified as Map +import Data.Some (Some) + import Data.Functor.Misc -import qualified Data.IntMap as IntMap -import qualified Data.Map as Map import Data.Monoid.DecidablyEmpty -#if !MIN_VERSION_base(4,11,0) -import Data.Semigroup (Semigroup (..)) -#endif -import Data.Some (Some) +import Data.Patch.Class +import Data.Patch.IntMap +import Data.Patch.Map -- | A set of changes to a 'DMap'. Any element may be inserted/updated or deleted. -- Insertions are represented as @'ComposeMaybe' (Just value)@, -- while deletions are represented as @'ComposeMaybe' Nothing@. -newtype PatchDMap k v = PatchDMap { unPatchDMap :: DMap k (ComposeMaybe v) } +newtype PatchDMap k v = PatchDMap {unPatchDMap :: DMap k (ComposeMaybe v)} -deriving instance GCompare k => Semigroup (PatchDMap k v) +deriving newtype instance GCompare k => Semigroup (PatchDMap k v) -deriving instance GCompare k => Monoid (PatchDMap k v) +deriving newtype instance GCompare k => Monoid (PatchDMap k v) -- It won't let me derive for some reason instance GCompare k => DecidablyEmpty (PatchDMap k v) where @@ -49,12 +38,13 @@ instance GCompare k => DecidablyEmpty (PatchDMap k v) where -- | Apply the insertions or deletions to a given 'DMap'. instance GCompare k => Patch (PatchDMap k v) where type PatchTarget (PatchDMap k v) = DMap k v - apply (PatchDMap diff) old = Just $! insertions `DMap.union` (old `DMap.difference` deletions) --TODO: return Nothing sometimes --Note: the strict application here is critical to ensuring that incremental merges don't hold onto all their prerequisite events forever; can we make this more robust? - where insertions = DMap.mapMaybeWithKey (const $ getComposeMaybe) diff - deletions = DMap.mapMaybeWithKey (const $ nothingToJust . getComposeMaybe) diff - nothingToJust = \case - Nothing -> Just $ Constant () - Just _ -> Nothing + apply (PatchDMap diff) old = Just $! insertions `DMap.union` (old `DMap.difference` deletions) -- TODO: return Nothing sometimes --Note: the strict application here is critical to ensuring that incremental merges don't hold onto all their prerequisite events forever; can we make this more robust? + where + insertions = DMap.mapMaybeWithKey (const getComposeMaybe) diff + deletions = DMap.mapMaybeWithKey (const $ nothingToJust . getComposeMaybe) diff + nothingToJust = \case + Nothing -> Just $ Constant () + Just _ -> Nothing -- | Map a function @v a -> v' a@ over any inserts/updates in the given -- @'PatchDMap' k v@ to produce a @'PatchDMap' k v'@. @@ -84,14 +74,16 @@ patchDMapToPatchMapWith f (PatchDMap p) = PatchMap $ dmapToMapWith (fmap f . get -- | Convert a @'PatchMap' k v@ into a @'PatchDMap' ('Const2' k a) v'@ using a function @v -> v' a@. const2PatchDMapWith :: forall k v v' a. (v -> v' a) -> PatchMap k v -> PatchDMap (Const2 k a) v' const2PatchDMapWith f (PatchMap p) = PatchDMap $ DMap.fromDistinctAscList $ g <$> Map.toAscList p - where g :: (k, Maybe v) -> DSum (Const2 k a) (ComposeMaybe v') - g (k, e) = Const2 k :=> ComposeMaybe (f <$> e) + where + g :: (k, Maybe v) -> DSum (Const2 k a) (ComposeMaybe v') + g (k, e) = Const2 k :=> ComposeMaybe (f <$> e) -- | Convert a @'PatchIntMap' v@ into a @'PatchDMap' ('Const2' Int a) v'@ using a function @v -> v' a@. const2IntPatchDMapWith :: forall v f a. (v -> f a) -> PatchIntMap v -> PatchDMap (Const2 IntMap.Key a) f const2IntPatchDMapWith f (PatchIntMap p) = PatchDMap $ DMap.fromDistinctAscList $ g <$> IntMap.toAscList p - where g :: (IntMap.Key, Maybe v) -> DSum (Const2 IntMap.Key a) (ComposeMaybe f) - g (k, e) = Const2 k :=> ComposeMaybe (f <$> e) + where + g :: (IntMap.Key, Maybe v) -> DSum (Const2 IntMap.Key a) (ComposeMaybe f) + g (k, e) = Const2 k :=> ComposeMaybe (f <$> e) -- | Get the values that will be replaced or deleted if the given patch is applied to the given 'DMap'. getDeletions :: GCompare k => PatchDMap k v -> DMap k v' -> DMap k v' diff --git a/src/Data/Patch/DMapWithMove.hs b/src/Data/Patch/DMapWithMove.hs index b2dcdd37..5fcd1ac6 100644 --- a/src/Data/Patch/DMapWithMove.hs +++ b/src/Data/Patch/DMapWithMove.hs @@ -1,48 +1,34 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE PatternGuards #-} -{-# LANGUAGE PolyKinds #-} -{-# LANGUAGE Rank2Types #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} -{-| -Description: A more advanced 'Patch' for 'DMap'. - -This Module contains @'PatchDMapWithMove' k v@ and associated functions, which -represents a 'Patch' to a @'DMap' k v@ which can insert, update, delete, and -move values between keys. --} +-- | +-- Description: A more advanced 'Patch' for 'DMap'. +-- +-- This Module contains @'PatchDMapWithMove' k v@ and associated functions, which +-- represents a 'Patch' to a @'DMap' k v@ which can insert, update, delete, and +-- move values between keys. module Data.Patch.DMapWithMove where -import Data.Patch.Class -import Data.Patch.MapWithMove (PatchMapWithMove (..)) -import qualified Data.Patch.MapWithMove as MapWithMove - import Data.Constraint.Extras import Data.Dependent.Map (DMap) +import Data.Dependent.Map qualified as DMap import Data.Dependent.Sum (DSum (..)) -import qualified Data.Dependent.Map as DMap import Data.Functor.Constant -import Data.Functor.Misc import Data.Functor.Product -import Data.GADT.Compare (GEq (..), GCompare (..)) +import Data.GADT.Compare (GCompare (..), GEq (..)) import Data.GADT.Show (GShow, gshow) import Data.Kind (Type) -import qualified Data.Map as Map +import Data.Map qualified as Map import Data.Maybe -import Data.Monoid.DecidablyEmpty -#if !MIN_VERSION_base(4,11,0) -import Data.Semigroup (Semigroup (..)) -#endif import Data.Some (Some, mkSome) import Data.These +import Data.Functor.Misc +import Data.Monoid.DecidablyEmpty +import Data.Patch.Class +import Data.Patch.MapWithMove (PatchMapWithMove (..)) +import Data.Patch.MapWithMove qualified as MapWithMove + -- | Like 'PatchMapWithMove', but for 'DMap'. Each key carries a 'NodeInfo' which describes how it will be changed by the patch and connects move sources and -- destinations. -- @@ -56,43 +42,43 @@ newtype PatchDMapWithMove k v = PatchDMapWithMove (DMap k (NodeInfo k v)) instance GCompare k => DecidablyEmpty (PatchDMapWithMove k v) where isEmpty (PatchDMapWithMove m) = DMap.null m --- |Structure which represents what changes apply to a particular key. @_nodeInfo_from@ specifies what happens to this key, and in particular what other key --- the current key is moving from, while @_nodeInfo_to@ specifies what key the current key is moving to if involved in a move. +-- | Structure which represents what changes apply to a particular key. @_nodeInfo_from@ specifies what happens to this key, and in particular what other key +-- the current key is moving from, while @_nodeInfo_to@ specifies what key the current key is moving to if involved in a move. data NodeInfo k v a = NodeInfo { _nodeInfo_from :: !(From k v a) - -- ^Change applying to the current key, be it an insert, move, or delete. + -- ^ Change applying to the current key, be it an insert, move, or delete. , _nodeInfo_to :: !(To k a) - -- ^Where this key is moving to, if involved in a move. Should only be @ComposeMaybe (Just k)@ when there is a corresponding 'From_Move'. + -- ^ Where this key is moving to, if involved in a move. Should only be @ComposeMaybe (Just k)@ when there is a corresponding 'From_Move'. } - deriving (Show) + deriving stock (Show) --- |Structure describing a particular change to a key, be it inserting a new key (@From_Insert@), updating an existing key (@From_Insert@ again), deleting a --- key (@From_Delete@), or moving a key (@From_Move@). +-- | Structure describing a particular change to a key, be it inserting a new key (@From_Insert@), updating an existing key (@From_Insert@ again), deleting a +-- key (@From_Delete@), or moving a key (@From_Move@). data From (k :: a -> Type) (v :: a -> Type) :: a -> Type where - -- |Insert a new or update an existing key with the given value @v a@ + -- | Insert a new or update an existing key with the given value @v a@ From_Insert :: v a -> From k v a - -- |Delete the existing key + -- | Delete the existing key From_Delete :: From k v a - -- |Move the value from the given key @k a@ to this key. The source key should also have an entry in the patch giving the current key as @_nodeInfo_to@, - -- usually but not necessarily with @From_Delete@. + -- | Move the value from the given key @k a@ to this key. The source key should also have an entry in the patch giving the current key as @_nodeInfo_to@, + -- usually but not necessarily with @From_Delete@. From_Move :: !(k a) -> From k v a - deriving (Show, Read, Eq, Ord) + deriving stock (Eq, Ord, Read, Show) --- |Type alias for the "to" part of a 'NodeInfo'. @'ComposeMaybe' ('Just' k)@ means the key is moving to another key, @ComposeMaybe Nothing@ for any other --- operation. +-- | Type alias for the "to" part of a 'NodeInfo'. @'ComposeMaybe' ('Just' k)@ means the key is moving to another key, @ComposeMaybe Nothing@ for any other +-- operation. type To = ComposeMaybe --- |Test whether a 'PatchDMapWithMove' satisfies its invariants. +-- | Test whether a 'PatchDMapWithMove' satisfies its invariants. validPatchDMapWithMove :: forall k v. (GCompare k, GShow k) => DMap k (NodeInfo k v) -> Bool validPatchDMapWithMove = not . null . validationErrorsForPatchDMapWithMove --- |Enumerate what reasons a 'PatchDMapWithMove' doesn't satisfy its invariants, returning @[]@ if it's valid. +-- | Enumerate what reasons a 'PatchDMapWithMove' doesn't satisfy its invariants, returning @[]@ if it's valid. validationErrorsForPatchDMapWithMove :: forall k v. (GCompare k, GShow k) => DMap k (NodeInfo k v) -> [String] validationErrorsForPatchDMapWithMove m = noSelfMoves <> movesBalanced where noSelfMoves = mapMaybe selfMove . DMap.toAscList $ m - selfMove (dst :=> NodeInfo (From_Move src) _) | Just _ <- dst `geq` src = Just $ "self move of key " <> gshow src <> " at destination side" + selfMove (dst :=> NodeInfo (From_Move src) _) | Just _ <- dst `geq` src = Just $ "self move of key " <> gshow src <> " at destination side" selfMove (src :=> NodeInfo _ (ComposeMaybe (Just dst))) | Just _ <- src `geq` dst = Just $ "self move of key " <> gshow dst <> " at source side" selfMove _ = Nothing movesBalanced = mapMaybe unbalancedMove . DMap.toAscList $ m @@ -112,24 +98,23 @@ validationErrorsForPatchDMapWithMove m = if isNothing (src' `geq` src) then Just $ "unbalanced move at source key " <> gshow src <> " to " <> gshow dst <> " is coming from " <> gshow src' <> " instead" else Nothing - _ -> Just $ "unbalanced move at source key " <> gshow src <> " supposedly going to " <> gshow dst <> " but destination key is not moving" unbalancedMove _ = Nothing --- |Test whether two @'PatchDMapWithMove' k v@ contain the same patch operations. +-- | Test whether two @'PatchDMapWithMove' k v@ contain the same patch operations. instance (GEq k, Has' Eq k (NodeInfo k v)) => Eq (PatchDMapWithMove k v) where - PatchDMapWithMove a == PatchDMapWithMove b = a == b + PatchDMapWithMove a == PatchDMapWithMove b = a == b --- |Higher kinded 2-tuple, identical to @Data.Functor.Product@ from base ≥ 4.9 +-- | Higher kinded 2-tuple, identical to @Data.Functor.Product@ from base ≥ 4.9 data Pair1 f g a = Pair1 (f a) (g a) --- |Helper data structure used for composing patches using the monoid instance. +-- | Helper data structure used for composing patches using the monoid instance. data Fixup k v a - = Fixup_Delete - | Fixup_Update (These (From k v a) (To k a)) + = Fixup_Delete + | Fixup_Update (These (From k v a) (To k a)) --- |Compose patches having the same effect as applying the patches in turn: @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@ +-- | Compose patches having the same effect as applying the patches in turn: @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@ instance GCompare k => Semigroup (PatchDMapWithMove k v) where PatchDMapWithMove ma <> PatchDMapWithMove mb = PatchDMapWithMove m where @@ -137,33 +122,38 @@ instance GCompare k => Semigroup (PatchDMapWithMove k v) where h :: DSum k (Pair1 (ComposeMaybe k) (From k v)) -> [DSum k (Fixup k v)] h (_ :=> Pair1 (ComposeMaybe mToAfter) editBefore) = case (mToAfter, editBefore) of (Just toAfter, From_Move fromBefore) - | isJust $ fromBefore `geq` toAfter - -> [toAfter :=> Fixup_Delete] - | otherwise - -> [ toAfter :=> Fixup_Update (This editBefore) - , fromBefore :=> Fixup_Update (That (ComposeMaybe mToAfter)) - ] + | isJust $ fromBefore `geq` toAfter -> + [toAfter :=> Fixup_Delete] + | otherwise -> + [ toAfter :=> Fixup_Update (This editBefore) + , fromBefore :=> Fixup_Update (That (ComposeMaybe mToAfter)) + ] (Nothing, From_Move fromBefore) -> [fromBefore :=> Fixup_Update (That (ComposeMaybe mToAfter))] -- The item is destroyed in the second patch, so indicate that it is destroyed in the source map (Just toAfter, _) -> [toAfter :=> Fixup_Update (This editBefore)] (Nothing, _) -> [] mergeFixups _ Fixup_Delete Fixup_Delete = Fixup_Delete mergeFixups _ (Fixup_Update a) (Fixup_Update b) - | This x <- a, That y <- b - = Fixup_Update $ These x y - | That y <- a, This x <- b - = Fixup_Update $ These x y + | This x <- a + , That y <- b = + Fixup_Update $ These x y + | That y <- a + , This x <- b = + Fixup_Update $ These x y mergeFixups _ _ _ = error "PatchDMapWithMove: incompatible fixups" - fixups = DMap.fromListWithKey mergeFixups $ concatMap h connections - combineNodeInfos _ nia nib = NodeInfo - { _nodeInfo_from = _nodeInfo_from nia - , _nodeInfo_to = _nodeInfo_to nib - } + fixups = DMap.fromListWithKey mergeFixups $ foldMap h connections + combineNodeInfos _ nia nib = + NodeInfo + { _nodeInfo_from = _nodeInfo_from nia + , _nodeInfo_to = _nodeInfo_to nib + } applyFixup _ ni = \case Fixup_Delete -> Nothing - Fixup_Update u -> Just $ NodeInfo - { _nodeInfo_from = fromMaybe (_nodeInfo_from ni) $ getHere u - , _nodeInfo_to = fromMaybe (_nodeInfo_to ni) $ getThere u - } + Fixup_Update u -> + Just $ + NodeInfo + { _nodeInfo_from = fromMaybe (_nodeInfo_from ni) $ getHere u + , _nodeInfo_to = fromMaybe (_nodeInfo_to ni) $ getThere u + } m = DMap.differenceWithKey applyFixup (DMap.unionWithKey combineNodeInfos ma mb) fixups getHere :: These a b -> Maybe a getHere = \case @@ -176,7 +166,7 @@ instance GCompare k => Semigroup (PatchDMapWithMove k v) where These _ b -> Just b That b -> Just b --- |Compose patches having the same effect as applying the patches in turn: @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@ +-- | Compose patches having the same effect as applying the patches in turn: @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@ instance GCompare k => Monoid (PatchDMapWithMove k v) where mempty = PatchDMapWithMove mempty mappend = (<>) @@ -203,42 +193,46 @@ PatchDMapWithMove dstAfter srcAfter `mappendPatchDMapWithMoveSlow` PatchDMapWith src = DMap.mapMaybeWithKey g $ DMap.union srcAfter srcBefore -} --- |Make a @'PatchDMapWithMove' k v@ which has the effect of inserting or updating a value @v a@ to the given key @k a@, like 'DMap.insert'. +-- | Make a @'PatchDMapWithMove' k v@ which has the effect of inserting or updating a value @v a@ to the given key @k a@, like 'DMap.insert'. insertDMapKey :: k a -> v a -> PatchDMapWithMove k v insertDMapKey k v = PatchDMapWithMove . DMap.singleton k $ NodeInfo (From_Insert v) (ComposeMaybe Nothing) --- |Make a @'PatchDMapWithMove' k v@ which has the effect of moving the value from the first key @k a@ to the second key @k a@, equivalent to: +-- | Make a @'PatchDMapWithMove' k v@ which has the effect of moving the value from the first key @k a@ to the second key @k a@, equivalent to: -- --- @ --- 'DMap.delete' src (maybe dmap ('DMap.insert' dst) (DMap.lookup src dmap)) --- @ +-- @ +-- 'DMap.delete' src (maybe dmap ('DMap.insert' dst) (DMap.lookup src dmap)) +-- @ moveDMapKey :: GCompare k => k a -> k a -> PatchDMapWithMove k v moveDMapKey src dst = case src `geq` dst of - Nothing -> PatchDMapWithMove $ DMap.fromList - [ dst :=> NodeInfo (From_Move src) (ComposeMaybe Nothing) - , src :=> NodeInfo From_Delete (ComposeMaybe $ Just dst) - ] + Nothing -> + PatchDMapWithMove $ + DMap.fromList + [ dst :=> NodeInfo (From_Move src) (ComposeMaybe Nothing) + , src :=> NodeInfo From_Delete (ComposeMaybe $ Just dst) + ] Just _ -> mempty --- |Make a @'PatchDMapWithMove' k v@ which has the effect of swapping two keys in the mapping, equivalent to: +-- | Make a @'PatchDMapWithMove' k v@ which has the effect of swapping two keys in the mapping, equivalent to: -- --- @ --- let aMay = DMap.lookup a dmap --- bMay = DMap.lookup b dmap --- in maybe id (DMap.insert a) (bMay <> aMay) --- . maybe id (DMap.insert b) (aMay <> bMay) --- . DMap.delete a . DMap.delete b $ dmap --- @ +-- @ +-- let aMay = DMap.lookup a dmap +-- bMay = DMap.lookup b dmap +-- in maybe id (DMap.insert a) (bMay <> aMay) +-- . maybe id (DMap.insert b) (aMay <> bMay) +-- . DMap.delete a . DMap.delete b $ dmap +-- @ swapDMapKey :: GCompare k => k a -> k a -> PatchDMapWithMove k v swapDMapKey src dst = case src `geq` dst of - Nothing -> PatchDMapWithMove $ DMap.fromList - [ dst :=> NodeInfo (From_Move src) (ComposeMaybe $ Just src) - , src :=> NodeInfo (From_Move dst) (ComposeMaybe $ Just dst) - ] + Nothing -> + PatchDMapWithMove $ + DMap.fromList + [ dst :=> NodeInfo (From_Move src) (ComposeMaybe $ Just src) + , src :=> NodeInfo (From_Move dst) (ComposeMaybe $ Just dst) + ] Just _ -> mempty --- |Make a @'PatchDMapWithMove' k v@ which has the effect of deleting a key in the mapping, equivalent to 'DMap.delete'. +-- | Make a @'PatchDMapWithMove' k v@ which has the effect of deleting a key in the mapping, equivalent to 'DMap.delete'. deleteDMapKey :: k a -> PatchDMapWithMove k v deleteDMapKey k = PatchDMapWithMove $ DMap.singleton k $ NodeInfo From_Delete $ ComposeMaybe Nothing @@ -266,88 +260,98 @@ dst (PatchDMapWithMove x _) = x src (PatchDMapWithMove _ x) = x -} --- |Extract the 'DMap' representing the patch changes from the 'PatchDMapWithMove'. +-- | Extract the 'DMap' representing the patch changes from the 'PatchDMapWithMove'. unPatchDMapWithMove :: PatchDMapWithMove k v -> DMap k (NodeInfo k v) unPatchDMapWithMove (PatchDMapWithMove p) = p --- |Wrap a 'DMap' representing patch changes into a 'PatchDMapWithMove', without checking any invariants. +-- | Wrap a 'DMap' representing patch changes into a 'PatchDMapWithMove', without checking any invariants. -- --- __Warning:__ when using this function, you must ensure that the invariants of 'PatchDMapWithMove' are preserved; they will not be checked. +-- __Warning:__ when using this function, you must ensure that the invariants of 'PatchDMapWithMove' are preserved; they will not be checked. unsafePatchDMapWithMove :: DMap k (NodeInfo k v) -> PatchDMapWithMove k v unsafePatchDMapWithMove = PatchDMapWithMove --- |Wrap a 'DMap' representing patch changes into a 'PatchDMapWithMove' while checking invariants. If the invariants are satisfied, @Right p@ is returned --- otherwise @Left errors@. +-- | Wrap a 'DMap' representing patch changes into a 'PatchDMapWithMove' while checking invariants. If the invariants are satisfied, @Right p@ is returned +-- otherwise @Left errors@. patchDMapWithMove :: (GCompare k, GShow k) => DMap k (NodeInfo k v) -> Either [String] (PatchDMapWithMove k v) patchDMapWithMove dm = case validationErrorsForPatchDMapWithMove dm of [] -> Right $ unsafePatchDMapWithMove dm errs -> Left errs --- |Map a natural transform @v -> v'@ over the given patch, transforming @'PatchDMapWithMove' k v@ into @'PatchDMapWithMove' k v'@. +-- | Map a natural transform @v -> v'@ over the given patch, transforming @'PatchDMapWithMove' k v@ into @'PatchDMapWithMove' k v'@. mapPatchDMapWithMove :: forall k v v'. (forall a. v a -> v' a) -> PatchDMapWithMove k v -> PatchDMapWithMove k v' -mapPatchDMapWithMove f (PatchDMapWithMove p) = PatchDMapWithMove $ - DMap.map (\ni -> ni { _nodeInfo_from = g $ _nodeInfo_from ni }) p - where g :: forall a. From k v a -> From k v' a - g = \case - From_Insert v -> From_Insert $ f v - From_Delete -> From_Delete - From_Move k -> From_Move k - --- |Traverse an effectful function @forall a. v a -> m (v ' a)@ over the given patch, transforming @'PatchDMapWithMove' k v@ into @m ('PatchDMapWithMove' k v')@. +mapPatchDMapWithMove f (PatchDMapWithMove p) = + PatchDMapWithMove $ + DMap.map (\ni -> ni {_nodeInfo_from = g $ _nodeInfo_from ni}) p + where + g :: forall a. From k v a -> From k v' a + g = \case + From_Insert v -> From_Insert $ f v + From_Delete -> From_Delete + From_Move k -> From_Move k + +-- | Traverse an effectful function @forall a. v a -> m (v ' a)@ over the given patch, transforming @'PatchDMapWithMove' k v@ into @m ('PatchDMapWithMove' k v')@. traversePatchDMapWithMove :: forall m k v v'. Applicative m => (forall a. v a -> m (v' a)) -> PatchDMapWithMove k v -> m (PatchDMapWithMove k v') traversePatchDMapWithMove f = traversePatchDMapWithMoveWithKey $ const f --- |Map an effectful function @forall a. k a -> v a -> m (v ' a)@ over the given patch, transforming @'PatchDMapWithMove' k v@ into @m ('PatchDMapWithMove' k v')@. +-- | Map an effectful function @forall a. k a -> v a -> m (v ' a)@ over the given patch, transforming @'PatchDMapWithMove' k v@ into @m ('PatchDMapWithMove' k v')@. traversePatchDMapWithMoveWithKey :: forall m k v v'. Applicative m => (forall a. k a -> v a -> m (v' a)) -> PatchDMapWithMove k v -> m (PatchDMapWithMove k v') traversePatchDMapWithMoveWithKey f (PatchDMapWithMove p) = PatchDMapWithMove <$> DMap.traverseWithKey (nodeInfoMapFromM . g) p - where g :: forall a. k a -> From k v a -> m (From k v' a) - g k = \case - From_Insert v -> From_Insert <$> f k v - From_Delete -> pure From_Delete - From_Move fromKey -> pure $ From_Move fromKey + where + g :: forall a. k a -> From k v a -> m (From k v' a) + g k = \case + From_Insert v -> From_Insert <$> f k v + From_Delete -> pure From_Delete + From_Move fromKey -> pure $ From_Move fromKey --- |Map a function which transforms @'From' k v a@ into a @'From' k v' a@ over a @'NodeInfo' k v a@. +-- | Map a function which transforms @'From' k v a@ into a @'From' k v' a@ over a @'NodeInfo' k v a@. nodeInfoMapFrom :: (From k v a -> From k v' a) -> NodeInfo k v a -> NodeInfo k v' a -nodeInfoMapFrom f ni = ni { _nodeInfo_from = f $ _nodeInfo_from ni } +nodeInfoMapFrom f ni = ni {_nodeInfo_from = f $ _nodeInfo_from ni} --- |Map an effectful function which transforms @'From' k v a@ into a @f ('From' k v' a)@ over a @'NodeInfo' k v a@. +-- | Map an effectful function which transforms @'From' k v a@ into a @f ('From' k v' a)@ over a @'NodeInfo' k v a@. nodeInfoMapFromM :: Functor f => (From k v a -> f (From k v' a)) -> NodeInfo k v a -> f (NodeInfo k v' a) -nodeInfoMapFromM f ni = fmap (\result -> ni { _nodeInfo_from = result }) $ f $ _nodeInfo_from ni +nodeInfoMapFromM f ni = fmap (\result -> ni {_nodeInfo_from = result}) $ f $ _nodeInfo_from ni --- |Weaken a 'PatchDMapWithMove' to a 'PatchMapWithMove' by weakening the keys from @k a@ to @'Some' k@ and applying a given weakening function @v a -> v'@ to --- values. +-- | Weaken a 'PatchDMapWithMove' to a 'PatchMapWithMove' by weakening the keys from @k a@ to @'Some' k@ and applying a given weakening function @v a -> v'@ to +-- values. weakenPatchDMapWithMoveWith :: forall k v v'. (forall a. v a -> v') -> PatchDMapWithMove k v -> PatchMapWithMove (Some k) v' weakenPatchDMapWithMoveWith f (PatchDMapWithMove p) = PatchMapWithMove $ weakenDMapWith g p - where g :: forall a. NodeInfo k v a -> MapWithMove.NodeInfo (Some k) v' - g ni = MapWithMove.NodeInfo - { MapWithMove._nodeInfo_from = case _nodeInfo_from ni of - From_Insert v -> MapWithMove.From_Insert $ f v - From_Delete -> MapWithMove.From_Delete - From_Move k -> MapWithMove.From_Move $ mkSome k - , MapWithMove._nodeInfo_to = mkSome <$> getComposeMaybe (_nodeInfo_to ni) - } + where + g :: forall a. NodeInfo k v a -> MapWithMove.NodeInfo (Some k) v' + g ni = + MapWithMove.NodeInfo + { MapWithMove._nodeInfo_from = case _nodeInfo_from ni of + From_Insert v -> MapWithMove.From_Insert $ f v + From_Delete -> MapWithMove.From_Delete + From_Move k -> MapWithMove.From_Move $ mkSome k + , MapWithMove._nodeInfo_to = mkSome <$> getComposeMaybe (_nodeInfo_to ni) + } --- |"Weaken" a @'PatchDMapWithMove' (Const2 k a) v@ to a @'PatchMapWithMove' k v'@. Weaken is in scare quotes because the 'Const2' has already disabled any --- dependency in the typing and all points are already @a@, hence the function to map each value to @v'@ is not higher rank. +-- | "Weaken" a @'PatchDMapWithMove' (Const2 k a) v@ to a @'PatchMapWithMove' k v'@. Weaken is in scare quotes because the 'Const2' has already disabled any +-- dependency in the typing and all points are already @a@, hence the function to map each value to @v'@ is not higher rank. patchDMapWithMoveToPatchMapWithMoveWith :: forall k v v' a. (v a -> v') -> PatchDMapWithMove (Const2 k a) v -> PatchMapWithMove k v' patchDMapWithMoveToPatchMapWithMoveWith f (PatchDMapWithMove p) = PatchMapWithMove $ dmapToMapWith g p - where g :: NodeInfo (Const2 k a) v a -> MapWithMove.NodeInfo k v' - g ni = MapWithMove.NodeInfo - { MapWithMove._nodeInfo_from = case _nodeInfo_from ni of - From_Insert v -> MapWithMove.From_Insert $ f v - From_Delete -> MapWithMove.From_Delete - From_Move (Const2 k) -> MapWithMove.From_Move k - , MapWithMove._nodeInfo_to = unConst2 <$> getComposeMaybe (_nodeInfo_to ni) - } + where + g :: NodeInfo (Const2 k a) v a -> MapWithMove.NodeInfo k v' + g ni = + MapWithMove.NodeInfo + { MapWithMove._nodeInfo_from = case _nodeInfo_from ni of + From_Insert v -> MapWithMove.From_Insert $ f v + From_Delete -> MapWithMove.From_Delete + From_Move (Const2 k) -> MapWithMove.From_Move k + , MapWithMove._nodeInfo_to = unConst2 <$> getComposeMaybe (_nodeInfo_to ni) + } --- |"Strengthen" a @'PatchMapWithMove' k v@ into a @'PatchDMapWithMove ('Const2' k a)@; that is, turn a non-dependently-typed patch into a dependently typed --- one but which always has a constant key type represented by 'Const2'. Apply the given function to each @v@ to produce a @v' a@. --- Completemented by 'patchDMapWithMoveToPatchMapWithMoveWith' +-- | "Strengthen" a @'PatchMapWithMove' k v@ into a @'PatchDMapWithMove ('Const2' k a)@; that is, turn a non-dependently-typed patch into a dependently typed +-- one but which always has a constant key type represented by 'Const2'. Apply the given function to each @v@ to produce a @v' a@. +-- Completemented by 'patchDMapWithMoveToPatchMapWithMoveWith' const2PatchDMapWithMoveWith :: forall k v v' a. (v -> v' a) -> PatchMapWithMove k v -> PatchDMapWithMove (Const2 k a) v' const2PatchDMapWithMoveWith f (PatchMapWithMove p) = PatchDMapWithMove $ DMap.fromDistinctAscList $ g <$> Map.toAscList p - where g :: (k, MapWithMove.NodeInfo k v) -> DSum (Const2 k a) (NodeInfo (Const2 k a) v') - g (k, ni) = Const2 k :=> NodeInfo + where + g :: (k, MapWithMove.NodeInfo k v) -> DSum (Const2 k a) (NodeInfo (Const2 k a) v') + g (k, ni) = + Const2 k + :=> NodeInfo { _nodeInfo_from = case MapWithMove._nodeInfo_from ni of MapWithMove.From_Insert v -> From_Insert $ f v MapWithMove.From_Delete -> From_Delete @@ -358,20 +362,22 @@ const2PatchDMapWithMoveWith f (PatchMapWithMove p) = PatchDMapWithMove $ DMap.fr -- | Apply the insertions, deletions, and moves to a given 'DMap'. instance GCompare k => Patch (PatchDMapWithMove k v) where type PatchTarget (PatchDMapWithMove k v) = DMap k v - apply (PatchDMapWithMove p) old = Just $! insertions `DMap.union` (old `DMap.difference` deletions) --TODO: return Nothing sometimes --Note: the strict application here is critical to ensuring that incremental merges don't hold onto all their prerequisite events forever; can we make this more robust? - where insertions = DMap.mapMaybeWithKey insertFunc p - insertFunc :: forall a. k a -> NodeInfo k v a -> Maybe (v a) - insertFunc _ ni = case _nodeInfo_from ni of - From_Insert v -> Just v - From_Move k -> DMap.lookup k old - From_Delete -> Nothing - deletions = DMap.mapMaybeWithKey deleteFunc p - deleteFunc :: forall a. k a -> NodeInfo k v a -> Maybe (Constant () a) - deleteFunc _ ni = case _nodeInfo_from ni of - From_Delete -> Just $ Constant () - _ -> Nothing + apply (PatchDMapWithMove p) old = Just $! insertions `DMap.union` (old `DMap.difference` deletions) -- TODO: return Nothing sometimes --Note: the strict application here is critical to ensuring that incremental merges don't hold onto all their prerequisite events forever; can we make this more robust? + where + insertions = DMap.mapMaybeWithKey insertFunc p + insertFunc :: forall a. k a -> NodeInfo k v a -> Maybe (v a) + insertFunc _ ni = case _nodeInfo_from ni of + From_Insert v -> Just v + From_Move k -> DMap.lookup k old + From_Delete -> Nothing + deletions = DMap.mapMaybeWithKey deleteFunc p + deleteFunc :: forall a. k a -> NodeInfo k v a -> Maybe (Constant () a) + deleteFunc _ ni = case _nodeInfo_from ni of + From_Delete -> Just $ Constant () + _ -> Nothing -- | Get the values that will be replaced, deleted, or moved if the given patch is applied to the given 'DMap'. getDeletionsAndMoves :: GCompare k => PatchDMapWithMove k v -> DMap k v' -> DMap k (Product v' (ComposeMaybe k)) getDeletionsAndMoves (PatchDMapWithMove p) m = DMap.intersectionWithKey f m p - where f _ v ni = Pair v $ _nodeInfo_to ni + where + f _ v ni = Pair v $ _nodeInfo_to ni diff --git a/src/Data/Patch/IntMap.hs b/src/Data/Patch/IntMap.hs index 8ffc52a6..66db1787 100644 --- a/src/Data/Patch/IntMap.hs +++ b/src/Data/Patch/IntMap.hs @@ -1,59 +1,50 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE DeriveTraversable #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE TypeOperators #-} -{-| -Description: Module containing 'PatchIntMap', a 'Patch' for 'IntMap'. - -Patches of this sort allow for insert/update or delete of associations. --} +-- | +-- Description: Module containing 'PatchIntMap', a 'Patch' for 'IntMap'. +-- +-- Patches of this sort allow for insert/update or delete of associations. module Data.Patch.IntMap where -import Control.Lens hiding (FunctorWithIndex, FoldableWithIndex, TraversableWithIndex) +import Control.Lens hiding (FoldableWithIndex, FunctorWithIndex, TraversableWithIndex) #if !MIN_VERSION_lens(5,0,0) -import qualified Control.Lens as L +import Control.Lens qualified as L #endif +import Data.Foldable.WithIndex +import Data.Functor.WithIndex import Data.IntMap.Strict (IntMap) -import qualified Data.IntMap.Strict as IntMap +import Data.IntMap.Strict qualified as IntMap import Data.Maybe +import Data.Traversable.WithIndex + import Data.Monoid.DecidablyEmpty -#if !MIN_VERSION_base(4,11,0) -import Data.Semigroup (Semigroup (..)) -#endif import Data.Patch.Class -import Data.Functor.WithIndex -import Data.Foldable.WithIndex -import Data.Traversable.WithIndex -- | 'Patch' for 'IntMap' which represents insertion or deletion of keys in the mapping. -- Internally represented by 'IntMap (Maybe a)', where @Just@ means insert/update -- and @Nothing@ means delete. -newtype PatchIntMap a = PatchIntMap { unPatchIntMap :: IntMap (Maybe a) } - deriving ( Show, Read, Eq, Ord - , Functor, Foldable, Traversable - , Monoid, DecidablyEmpty - ) +newtype PatchIntMap a = PatchIntMap {unPatchIntMap :: IntMap (Maybe a)} + deriving stock (Foldable, Functor, Read, Show, Traversable) + deriving newtype (DecidablyEmpty, Eq, Monoid, Ord) -- | @a <> b@ will apply the changes of @b@ and then apply the changes of @a@. -- If the same key is modified by both patches, the one on the left will take -- precedence. -deriving instance Semigroup (PatchIntMap v) +deriving newtype instance Semigroup (PatchIntMap v) makeWrapped ''PatchIntMap -- | Apply the insertions or deletions to a given 'IntMap'. instance Patch (PatchIntMap a) where type PatchTarget (PatchIntMap a) = IntMap a - apply (PatchIntMap p) v = if IntMap.null p then Nothing else Just $! - let removes = IntMap.filter isNothing p - adds = IntMap.mapMaybe id p - in IntMap.union adds $ v `IntMap.difference` removes + apply (PatchIntMap p) v = + if IntMap.null p + then Nothing + else + Just $! + let removes = IntMap.filter isNothing p + adds = IntMap.mapMaybe id p + in IntMap.union adds $ v `IntMap.difference` removes instance FunctorWithIndex Int PatchIntMap instance FoldableWithIndex Int PatchIntMap @@ -69,7 +60,7 @@ instance L.TraversableWithIndex Int PatchIntMap where itraverse = Data.Traversab -- | Map a function @Int -> a -> b@ over all @a@s in the given @'PatchIntMap' a@ -- (that is, all inserts/updates), producing a @PatchIntMap b@. mapIntMapPatchWithKey :: (Int -> a -> b) -> PatchIntMap a -> PatchIntMap b -mapIntMapPatchWithKey f (PatchIntMap m) = PatchIntMap $ IntMap.mapWithKey (\ k mv -> f k <$> mv) m +mapIntMapPatchWithKey f (PatchIntMap m) = PatchIntMap $ IntMap.mapWithKey (\k mv -> f k <$> mv) m -- | Map an effectful function @Int -> a -> f b@ over all @a@s in the given @'PatchIntMap' a@ -- (that is, all inserts/updates), producing a @f (PatchIntMap b)@. diff --git a/src/Data/Patch/Map.hs b/src/Data/Patch/Map.hs index c240460b..43a80c8d 100644 --- a/src/Data/Patch/Map.hs +++ b/src/Data/Patch/Map.hs @@ -1,70 +1,60 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE DeriveTraversable #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE TypeOperators #-} -{-| -Description: A basic 'Patch' on 'Map' - -Patches of this type consist only of insertions (including overwrites) and -deletions. --} +-- | +-- Description: A basic 'Patch' on 'Map' +-- +-- Patches of this type consist only of insertions (including overwrites) and +-- deletions. module Data.Patch.Map where -import Data.Patch.Class - -import Control.Lens hiding (FunctorWithIndex, FoldableWithIndex, TraversableWithIndex) -#if !MIN_VERSION_lens(5,0,0) -import qualified Control.Lens as L -#endif +import Control.Lens hiding (FoldableWithIndex, FunctorWithIndex, TraversableWithIndex) +import Data.Foldable (toList) +import Data.Foldable.WithIndex +import Data.Functor.WithIndex import Data.Map (Map) -import qualified Data.Map as Map +import Data.Map qualified as Map import Data.Maybe -import Data.Monoid.DecidablyEmpty import Data.Semigroup (Semigroup (..), stimesIdempotentMonoid) -import Data.Functor.WithIndex -import Data.Foldable.WithIndex import Data.Traversable.WithIndex +import Data.Monoid.DecidablyEmpty +import Data.Patch.Class +#if !MIN_VERSION_lens(5,0,0) +import Control.Lens qualified as L +#endif + -- | A set of changes to a 'Map'. Any element may be inserted/updated or -- deleted. Insertions are represented as values wrapped in 'Just', while -- deletions are represented as 'Nothing's -newtype PatchMap k v = PatchMap { unPatchMap :: Map k (Maybe v) } - deriving ( Show, Read, Eq, Ord - , Foldable, Traversable - , DecidablyEmpty - ) +newtype PatchMap k v = PatchMap {unPatchMap :: Map k (Maybe v)} + deriving stock (Foldable, Read, Show, Traversable) + deriving newtype (DecidablyEmpty, Eq, Ord) -- | 'fmap'ping a 'PatchMap' will alter all of the values it will insert. -- Deletions are unaffected. -deriving instance Functor (PatchMap k) +deriving stock instance Functor (PatchMap k) + -- | The empty 'PatchMap' contains no insertions or deletions -deriving instance Ord k => Monoid (PatchMap k v) +deriving newtype instance Ord k => Monoid (PatchMap k v) -- | @a <> b@ will apply the changes of @b@ and then apply the changes of @a@. -- If the same key is modified by both patches, the one on the left will take -- precedence. instance Ord k => Semigroup (PatchMap k v) where - PatchMap a <> PatchMap b = PatchMap $ a `mappend` b --TODO: Add a semigroup instance for Map - -- PatchMap is idempotent, so stimes n is id for every n - stimes = stimesIdempotentMonoid + PatchMap a <> PatchMap b = PatchMap $ a <> b -- TODO: Add a semigroup instance for Map + stimes = stimesIdempotentMonoid -- PatchMap is idempotent, so stimes n is id for every n -- | Apply the insertions or deletions to a given 'Map'. instance Ord k => Patch (PatchMap k v) where type PatchTarget (PatchMap k v) = Map k v - {-# INLINABLE apply #-} - apply (PatchMap p) old = Just $! insertions `Map.union` (old `Map.difference` deletions) --TODO: return Nothing sometimes --Note: the strict application here is critical to ensuring that incremental merges don't hold onto all their prerequisite events forever; can we make this more robust? - where insertions = Map.mapMaybeWithKey (const id) p - deletions = Map.mapMaybeWithKey (const nothingToJust) p - nothingToJust = \case - Nothing -> Just () - Just _ -> Nothing + {-# INLINEABLE apply #-} + apply (PatchMap p) old = Just $! insertions `Map.union` (old `Map.difference` deletions) -- TODO: return Nothing sometimes --Note: the strict application here is critical to ensuring that incremental merges don't hold onto all their prerequisite events forever; can we make this more robust? + where + insertions = Map.mapMaybeWithKey (const id) p + deletions = Map.mapMaybeWithKey (const nothingToJust) p + nothingToJust = \case + Nothing -> Just () + Just _ -> Nothing makeWrapped ''PatchMap @@ -81,7 +71,7 @@ instance L.TraversableWithIndex k (PatchMap k) where itraverse = Data.Traversabl -- | Returns all the new elements that will be added to the 'Map' patchMapNewElements :: PatchMap k v -> [v] -patchMapNewElements (PatchMap p) = catMaybes $ Map.elems p +patchMapNewElements (PatchMap p) = catMaybes $ toList p -- | Returns all the new elements that will be added to the 'Map' patchMapNewElementsMap :: PatchMap k v -> Map k v diff --git a/src/Data/Patch/MapWithMove.hs b/src/Data/Patch/MapWithMove.hs index 5a9aa81c..b5b73f38 100644 --- a/src/Data/Patch/MapWithMove.hs +++ b/src/Data/Patch/MapWithMove.hs @@ -1,32 +1,16 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE DeriveTraversable #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE PatternGuards #-} -{-# LANGUAGE PatternSynonyms #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} - -{-| -Description: An intermediate 'Patch' on 'Map' - -Patches of this type can insert, delete, and also move values from one key to -another. --} + +-- | +-- Description: An intermediate 'Patch' on 'Map' +-- +-- Patches of this type can insert, delete, and also move values from one key to +-- another. module Data.Patch.MapWithMove ( PatchMapWithMove - ( PatchMapWithMove - , unPatchMapWithMove - , .. - ) + ( PatchMapWithMove + , unPatchMapWithMove + , .. + ) , patchMapWithMove , patchMapWithMoveInsertAll , insertMapKey @@ -40,7 +24,7 @@ module Data.Patch.MapWithMove , patchThatChangesAndSortsMapWith , patchThatChangesMap - -- * Node Info + -- * Node Info , NodeInfo ( NodeInfo , _nodeInfo_from @@ -52,7 +36,7 @@ module Data.Patch.MapWithMove , nodeInfoMapMFrom , nodeInfoSetTo - -- * From + -- * From , From ( From_Insert , From_Delete @@ -61,61 +45,62 @@ module Data.Patch.MapWithMove ) , bitraverseFrom - -- * To + -- * To , To ) where +-- already a transparent synonym + +import Control.Lens hiding (FoldableWithIndex, FunctorWithIndex, TraversableWithIndex) import Data.Coerce +import Data.Foldable.WithIndex +import Data.Functor.WithIndex import Data.Kind (Type) -import Data.Patch.Class -import Data.Patch.MapWithPatchingMove (PatchMapWithPatchingMove(..), To) -import qualified Data.Patch.MapWithPatchingMove as PM -- already a transparent synonym - -import Control.Lens hiding (FunctorWithIndex, FoldableWithIndex, TraversableWithIndex) -#if !MIN_VERSION_lens(5,0,0) -import qualified Control.Lens as L -#endif import Data.List import Data.Map (Map) -import qualified Data.Map as Map +import Data.Map qualified as Map import Data.Proxy -#if !MIN_VERSION_base(4,11,0) -import Data.Semigroup (Semigroup (..)) -#endif import Data.Traversable (foldMapDefault) -import Data.Functor.WithIndex -import Data.Foldable.WithIndex import Data.Traversable.WithIndex +import Data.Patch.Class +import Data.Patch.MapWithPatchingMove (PatchMapWithPatchingMove (..), To) +import Data.Patch.MapWithPatchingMove qualified as PM +#if !MIN_VERSION_lens(5,0,0) +import Control.Lens qualified as L +#endif + -- | Patch a Map with additions, deletions, and moves. Invariant: If key @k1@ -- is coming from @From_Move k2@, then key @k2@ should be going to @Just k1@, -- and vice versa. There should never be any unpaired From/To keys. newtype PatchMapWithMove k (v :: Type) = PatchMapWithMove' - { -- | Extract the underlying 'PatchMapWithPatchingMove k (Proxy v)' - unPatchMapWithMove' :: PatchMapWithPatchingMove k (Proxy v) + { unPatchMapWithMove' :: PatchMapWithPatchingMove k (Proxy v) + -- ^ Extract the underlying 'PatchMapWithPatchingMove k (Proxy v)' } - deriving ( Show, Read, Eq, Ord --- Haddock cannot handle documentation here before GHC 8.6 - , -#if __GLASGOW_HASKELL__ >= 806 - -- | Compose patches having the same effect as applying the - -- patches in turn: @'applyAlways' (p <> q) == 'applyAlways' p . - -- 'applyAlways' q@ -#endif - Semigroup - , Monoid - ) + deriving stock (Read, Show) + deriving newtype + ( Semigroup + -- ^ Compose patches having the same effect as applying the + -- patches in turn: @'applyAlways' (p <> q) == 'applyAlways' p . + -- 'applyAlways' q@ + , Eq + , Monoid + , Ord + ) pattern Coerce :: Coercible a b => a -> b pattern Coerce x <- (coerce -> x) - where Coerce x = coerce x + where + Coerce x = coerce x {-# COMPLETE PatchMapWithMove #-} pattern PatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v + -- | Extract the representation of the t'PatchMapWithMove' as a map of -- t'NodeInfo'. unPatchMapWithMove :: PatchMapWithMove k v -> Map k (NodeInfo k v) -pattern PatchMapWithMove { unPatchMapWithMove } = PatchMapWithMove' (PatchMapWithPatchingMove (Coerce unPatchMapWithMove)) + +pattern PatchMapWithMove {unPatchMapWithMove} = PatchMapWithMove' (PatchMapWithPatchingMove (Coerce unPatchMapWithMove)) _PatchMapWithMove :: Iso @@ -133,9 +118,9 @@ instance Foldable (PatchMapWithMove k) where instance Traversable (PatchMapWithMove k) where traverse = - _PatchMapWithMove . - traverse . - traverse + _PatchMapWithMove + . traverse + . traverse instance FunctorWithIndex k (PatchMapWithMove k) instance FoldableWithIndex k (PatchMapWithMove k) @@ -160,27 +145,27 @@ patchMapWithMoveInsertAll = PatchMapWithMove' . PM.patchMapWithPatchingMoveInser insertMapKey :: k -> v -> PatchMapWithMove k v insertMapKey k v = PatchMapWithMove' $ PM.insertMapKey k v --- |Make a @t'PatchMapWithMove' k v@ which has the effect of moving the value from the first key @k@ to the second key @k@, equivalent to: +-- | Make a @t'PatchMapWithMove' k v@ which has the effect of moving the value from the first key @k@ to the second key @k@, equivalent to: -- --- @ --- 'Map.delete' src (maybe map ('Map.insert' dst) (Map.lookup src map)) --- @ +-- @ +-- 'Map.delete' src (maybe map ('Map.insert' dst) (Map.lookup src map)) +-- @ moveMapKey :: Ord k => k -> k -> PatchMapWithMove k v moveMapKey src dst = PatchMapWithMove' $ PM.moveMapKey src dst --- |Make a @t'PatchMapWithMove' k v@ which has the effect of swapping two keys in the mapping, equivalent to: +-- | Make a @t'PatchMapWithMove' k v@ which has the effect of swapping two keys in the mapping, equivalent to: -- --- @ --- let aMay = Map.lookup a map --- bMay = Map.lookup b map --- in maybe id (Map.insert a) (bMay <> aMay) --- . maybe id (Map.insert b) (aMay <> bMay) --- . Map.delete a . Map.delete b $ map --- @ +-- @ +-- let aMay = Map.lookup a map +-- bMay = Map.lookup b map +-- in maybe id (Map.insert a) (bMay <> aMay) +-- . maybe id (Map.insert b) (aMay <> bMay) +-- . Map.delete a . Map.delete b $ map +-- @ swapMapKey :: Ord k => k -> k -> PatchMapWithMove k v swapMapKey src dst = PatchMapWithMove' $ PM.swapMapKey src dst --- |Make a @t'PatchMapWithMove' k v@ which has the effect of deleting a key in the mapping, equivalent to 'Map.delete'. +-- | Make a @t'PatchMapWithMove' k v@ which has the effect of deleting a key in the mapping, equivalent to 'Map.delete'. deleteMapKey :: k -> PatchMapWithMove k v deleteMapKey = PatchMapWithMove' . PM.deleteMapKey @@ -214,14 +199,16 @@ patchThatSortsMapWith cmp = PatchMapWithMove' . PM.patchThatSortsMapWith cmp -- values sorted with the given ordering function. patchThatChangesAndSortsMapWith :: (Ord k, Ord v) => (v -> v -> Ordering) -> Map k v -> Map k v -> PatchMapWithMove k v patchThatChangesAndSortsMapWith cmp oldByIndex newByIndexUnsorted = patchThatChangesMap oldByIndex newByIndex - where newList = Map.toList newByIndexUnsorted - newByIndex = Map.fromList $ zip (fst <$> newList) $ sortBy cmp $ snd <$> newList + where + newList = Map.toList newByIndexUnsorted + newByIndex = Map.fromList $ zip (fst <$> newList) $ sortBy cmp $ snd <$> newList -- | Create a t'PatchMapWithMove' that, if applied to the first 'Map' provided, -- will produce the second 'Map'. patchThatChangesMap :: (Ord k, Ord v) => Map k v -> Map k v -> PatchMapWithMove k v -patchThatChangesMap oldByIndex newByIndex = PatchMapWithMove' $ - PM.patchThatChangesMap oldByIndex newByIndex +patchThatChangesMap oldByIndex newByIndex = + PatchMapWithMove' $ + PM.patchThatChangesMap oldByIndex newByIndex -- -- NodeInfo @@ -229,22 +216,23 @@ patchThatChangesMap oldByIndex newByIndex = PatchMapWithMove' $ -- | Holds the information about each key: where its new value should come from, -- and where its old value should go to -newtype NodeInfo k (v :: Type) = NodeInfo' { unNodeInfo' :: PM.NodeInfo k (Proxy v) } +newtype NodeInfo k (v :: Type) = NodeInfo' {unNodeInfo' :: PM.NodeInfo k (Proxy v)} -deriving instance (Show k, Show p) => Show (NodeInfo k p) -deriving instance (Read k, Read p) => Read (NodeInfo k p) -deriving instance (Eq k, Eq p) => Eq (NodeInfo k p) -deriving instance (Ord k, Ord p) => Ord (NodeInfo k p) +deriving stock instance (Show k, Show p) => Show (NodeInfo k p) +deriving stock instance (Read k, Read p) => Read (NodeInfo k p) +deriving newtype instance (Eq k, Eq p) => Eq (NodeInfo k p) +deriving newtype instance (Ord k, Ord p) => Ord (NodeInfo k p) {-# COMPLETE NodeInfo #-} pattern NodeInfo :: From k v -> To k -> NodeInfo k v _nodeInfo_from :: NodeInfo k v -> From k v _nodeInfo_to :: NodeInfo k v -> To k -pattern NodeInfo { _nodeInfo_from, _nodeInfo_to } = NodeInfo' - PM.NodeInfo - { PM._nodeInfo_from = Coerce _nodeInfo_from - , PM._nodeInfo_to = _nodeInfo_to - } +pattern NodeInfo {_nodeInfo_from, _nodeInfo_to} = + NodeInfo' + PM.NodeInfo + { PM._nodeInfo_from = Coerce _nodeInfo_from + , PM._nodeInfo_to = _nodeInfo_to + } _NodeInfo :: Iso @@ -268,10 +256,12 @@ bitraverseNodeInfo :: Applicative f => (k0 -> f k1) -> (v0 -> f v1) - -> NodeInfo k0 v0 -> f (NodeInfo k1 v1) -bitraverseNodeInfo fk fv = fmap NodeInfo' - . PM.bitraverseNodeInfo fk (\ ~Proxy -> pure Proxy) fv - . coerce + -> NodeInfo k0 v0 + -> f (NodeInfo k1 v1) +bitraverseNodeInfo fk fv = + fmap NodeInfo' + . PM.bitraverseNodeInfo fk (\ ~Proxy -> pure Proxy) fv + . coerce -- | Change the 'From' value of a t'NodeInfo' nodeInfoMapFrom :: (From k v -> From k v) -> NodeInfo k v -> NodeInfo k v @@ -282,10 +272,12 @@ nodeInfoMapFrom f = coerce $ PM.nodeInfoMapFrom (unFrom' . f . From') nodeInfoMapMFrom :: Functor f => (From k v -> f (From k v)) - -> NodeInfo k v -> f (NodeInfo k v) -nodeInfoMapMFrom f = fmap NodeInfo' - . PM.nodeInfoMapMFrom (fmap unFrom' . f . From') - . coerce + -> NodeInfo k v + -> f (NodeInfo k v) +nodeInfoMapMFrom f = + fmap NodeInfo' + . PM.nodeInfoMapMFrom (fmap unFrom' . f . From') + . coerce -- | Set the 'To' field of a t'NodeInfo' nodeInfoSetTo :: To k -> NodeInfo k v -> NodeInfo k v @@ -296,7 +288,7 @@ nodeInfoSetTo = coerce . PM.nodeInfoSetTo -- -- | Describe how a key's new value should be produced -newtype From k (v :: Type) = From' { unFrom' :: PM.From k (Proxy v) } +newtype From k (v :: Type) = From' {unFrom' :: PM.From k (Proxy v)} {-# COMPLETE From_Insert, From_Delete, From_Move #-} @@ -317,10 +309,12 @@ bitraverseFrom :: Applicative f => (k0 -> f k1) -> (v0 -> f v1) - -> From k0 v0 -> f (From k1 v1) -bitraverseFrom fk fv = fmap From' - . PM.bitraverseFrom fk (\ ~Proxy -> pure Proxy) fv - . coerce + -> From k0 v0 + -> f (From k1 v1) +bitraverseFrom fk fv = + fmap From' + . PM.bitraverseFrom fk (\ ~Proxy -> pure Proxy) fv + . coerce makeWrapped ''PatchMapWithMove makeWrapped ''NodeInfo diff --git a/src/Data/Patch/MapWithPatchingMove.hs b/src/Data/Patch/MapWithPatchingMove.hs index 82aaf26e..fc6d0f0e 100644 --- a/src/Data/Patch/MapWithPatchingMove.hs +++ b/src/Data/Patch/MapWithPatchingMove.hs @@ -1,23 +1,11 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE PatternGuards #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} -{-| -Description: An advanced 'Patch' on 'Map' - -Patches of this type can can insert, delete, and move values from one key to -another, and move patches may also additionally patch the value being moved. --} +-- | +-- Description: An advanced 'Patch' on 'Map' +-- +-- Patches of this type can can insert, delete, and move values from one key to +-- another, and move patches may also additionally patch the value being moved. module Data.Patch.MapWithPatchingMove ( PatchMapWithPatchingMove (..) , patchMapWithPatchingMove @@ -34,26 +22,23 @@ module Data.Patch.MapWithPatchingMove , patchThatChangesAndSortsMapWith , patchThatChangesMap - -- * Node Info + -- * Node Info , NodeInfo (..) , bitraverseNodeInfo , nodeInfoMapFrom , nodeInfoMapMFrom , nodeInfoSetTo - -- * From - , From(..) + -- * From + , From (..) , bitraverseFrom - -- * To + -- * To , To - -- TODO internals module , Fixup (..) ) where -import Data.Patch.Class - import Control.Lens ((<&>)) import Control.Lens.TH (makeWrapped) import Data.Align (align) @@ -61,118 +46,112 @@ import Data.Foldable (toList) import Data.Function import Data.List import Data.Map (Map) -import qualified Data.Map as Map +import Data.Map qualified as Map import Data.Maybe -#if !MIN_VERSION_base(4,11,0) -import Data.Semigroup (Semigroup (..)) -#endif -import Data.Monoid.DecidablyEmpty import Data.Set (Set) -import qualified Data.Set as Set +import Data.Set qualified as Set import Data.These (These (..)) +import Data.Monoid.DecidablyEmpty +import Data.Patch.Class + -- | Patch a Map with additions, deletions, and moves. Invariant: If key @k1@ -- is coming from @From_Move k2@, then key @k2@ should be going to @Just k1@, -- and vice versa. There should never be any unpaired From/To keys. newtype PatchMapWithPatchingMove k p = PatchMapWithPatchingMove - { -- | Extract the internal representation of the 'PatchMapWithPatchingMove' - unPatchMapWithPatchingMove :: Map k (NodeInfo k p) + { unPatchMapWithPatchingMove :: Map k (NodeInfo k p) + -- ^ Extract the internal representation of the 'PatchMapWithPatchingMove' } -deriving instance (Show k, Show p, Show (PatchTarget p)) => Show (PatchMapWithPatchingMove k p) -deriving instance (Ord k, Read k, Read p, Read (PatchTarget p)) => Read (PatchMapWithPatchingMove k p) -deriving instance (Eq k, Eq p, Eq (PatchTarget p)) => Eq (PatchMapWithPatchingMove k p) -deriving instance (Ord k, Ord p, Ord (PatchTarget p)) => Ord (PatchMapWithPatchingMove k p) +deriving stock instance (Show k, Show p, Show (PatchTarget p)) => Show (PatchMapWithPatchingMove k p) +deriving stock instance (Ord k, Read k, Read p, Read (PatchTarget p)) => Read (PatchMapWithPatchingMove k p) +deriving newtype instance (Eq k, Eq p, Eq (PatchTarget p)) => Eq (PatchMapWithPatchingMove k p) +deriving newtype instance (Ord k, Ord p, Ord (PatchTarget p)) => Ord (PatchMapWithPatchingMove k p) -deriving instance ( Ord k -#if !MIN_VERSION_base(4,11,0) - , Semigroup p -#endif - , DecidablyEmpty p - , Patch p - ) => DecidablyEmpty (PatchMapWithPatchingMove k p) +deriving newtype instance + ( Ord k + , DecidablyEmpty p + , Patch p + ) + => DecidablyEmpty (PatchMapWithPatchingMove k p) -- | Create a 'PatchMapWithPatchingMove', validating it patchMapWithPatchingMove :: Ord k => Map k (NodeInfo k p) -> Maybe (PatchMapWithPatchingMove k p) patchMapWithPatchingMove m = if valid then Just $ PatchMapWithPatchingMove m else Nothing - where valid = forwardLinks == backwardLinks - forwardLinks = Map.mapMaybe _nodeInfo_to m - backwardLinks = Map.fromList $ catMaybes $ flip fmap (Map.toList m) $ \(to, p) -> - case _nodeInfo_from p of - From_Move from _ -> Just (from, to) - _ -> Nothing + where + valid = forwardLinks == backwardLinks + forwardLinks = Map.mapMaybe _nodeInfo_to m + backwardLinks = Map.fromList $ catMaybes $ flip fmap (Map.toList m) $ \(to, p) -> + case _nodeInfo_from p of + From_Move from _ -> Just (from, to) + _ -> Nothing -- | Create a 'PatchMapWithPatchingMove' that inserts everything in the given 'Map' patchMapWithPatchingMoveInsertAll :: Map k (PatchTarget p) -> PatchMapWithPatchingMove k p -patchMapWithPatchingMoveInsertAll m = PatchMapWithPatchingMove $ flip fmap m $ \v -> NodeInfo - { _nodeInfo_from = From_Insert v - , _nodeInfo_to = Nothing - } +patchMapWithPatchingMoveInsertAll m = PatchMapWithPatchingMove $ flip fmap m $ \v -> + NodeInfo + { _nodeInfo_from = From_Insert v + , _nodeInfo_to = Nothing + } -- | Make a @'PatchMapWithPatchingMove' k p@ which has the effect of inserting or replacing a value @v@ at the given key @k@, like 'Map.insert'. insertMapKey :: k -> PatchTarget p -> PatchMapWithPatchingMove k p insertMapKey k v = PatchMapWithPatchingMove . Map.singleton k $ NodeInfo (From_Insert v) Nothing --- |Make a @'PatchMapWithPatchingMove' k p@ which has the effect of moving the value from the first key @k@ to the second key @k@, equivalent to: +-- | Make a @'PatchMapWithPatchingMove' k p@ which has the effect of moving the value from the first key @k@ to the second key @k@, equivalent to: -- --- @ --- 'Map.delete' src (maybe map ('Map.insert' dst) (Map.lookup src map)) --- @ +-- @ +-- 'Map.delete' src (maybe map ('Map.insert' dst) (Map.lookup src map)) +-- @ moveMapKey :: ( DecidablyEmpty p -#if !MIN_VERSION_base(4,11,0) - , Semigroup p -#endif , Patch p ) - => Ord k => k -> k -> PatchMapWithPatchingMove k p + => Ord k + => k -> k -> PatchMapWithPatchingMove k p moveMapKey src dst | src == dst = mempty | otherwise = - PatchMapWithPatchingMove $ Map.fromList - [ (dst, NodeInfo (From_Move src mempty) Nothing) - , (src, NodeInfo From_Delete (Just dst)) - ] + PatchMapWithPatchingMove $ + Map.fromList + [ (dst, NodeInfo (From_Move src mempty) Nothing) + , (src, NodeInfo From_Delete (Just dst)) + ] patchMapKey - :: ( DecidablyEmpty p -#if !MIN_VERSION_base(4,11,0) - , Semigroup p -#endif - ) + :: DecidablyEmpty p => k -> p -> PatchMapWithPatchingMove k p patchMapKey k p | isEmpty p = PatchMapWithPatchingMove Map.empty | otherwise = PatchMapWithPatchingMove $ Map.singleton k $ NodeInfo (From_Move k p) (Just k) --- |Make a @'PatchMapWithPatchingMove' k p@ which has the effect of swapping two keys in the mapping, equivalent to: +-- | Make a @'PatchMapWithPatchingMove' k p@ which has the effect of swapping two keys in the mapping, equivalent to: -- --- @ --- let aMay = Map.lookup a map --- bMay = Map.lookup b map --- in maybe id (Map.insert a) (bMay <> aMay) --- . maybe id (Map.insert b) (aMay <> bMay) --- . Map.delete a . Map.delete b $ map --- @ +-- @ +-- let aMay = Map.lookup a map +-- bMay = Map.lookup b map +-- in maybe id (Map.insert a) (bMay <> aMay) +-- . maybe id (Map.insert b) (aMay <> bMay) +-- . Map.delete a . Map.delete b $ map +-- @ swapMapKey :: ( DecidablyEmpty p -#if !MIN_VERSION_base(4,11,0) - , Semigroup p -#endif , Patch p ) - => Ord k => k -> k -> PatchMapWithPatchingMove k p + => Ord k + => k -> k -> PatchMapWithPatchingMove k p swapMapKey src dst | src == dst = mempty | otherwise = - PatchMapWithPatchingMove $ Map.fromList - [ (dst, NodeInfo (From_Move src mempty) (Just src)) - , (src, NodeInfo (From_Move dst mempty) (Just dst)) - ] + PatchMapWithPatchingMove $ + Map.fromList + [ (dst, NodeInfo (From_Move src mempty) (Just src)) + , (src, NodeInfo (From_Move dst mempty) (Just dst)) + ] -- | Make a @'PatchMapWithPatchingMove' k v@ which has the effect of deleting a key in -- the mapping, equivalent to 'Map.delete'. @@ -190,32 +169,35 @@ unsafePatchMapWithPatchingMove = PatchMapWithPatchingMove -- | Apply the insertions, deletions, and moves to a given 'Map' instance (Ord k, Patch p) => Patch (PatchMapWithPatchingMove k p) where type PatchTarget (PatchMapWithPatchingMove k p) = Map k (PatchTarget p) + -- TODO: return Nothing sometimes -- Note: the strict application here is critical to ensuring that incremental -- merges don't hold onto all their prerequisite events forever; can we make -- this more robust? apply (PatchMapWithPatchingMove m) old = Just $! insertions `Map.union` (old `Map.difference` deletions) - where insertions = flip Map.mapMaybeWithKey m $ \_ ni -> case _nodeInfo_from ni of - From_Insert v -> Just v - From_Move k p -> applyAlways p <$> Map.lookup k old - From_Delete -> Nothing - deletions = flip Map.mapMaybeWithKey m $ \_ ni -> case _nodeInfo_from ni of - From_Delete -> Just () - _ -> Nothing + where + insertions = flip Map.mapMaybeWithKey m $ \_ ni -> case _nodeInfo_from ni of + From_Insert v -> Just v + From_Move k p -> applyAlways p <$> Map.lookup k old + From_Delete -> Nothing + deletions = flip Map.mapMaybeWithKey m $ \_ ni -> case _nodeInfo_from ni of + From_Delete -> Just () + _ -> Nothing -- | Returns all the new elements that will be added to the 'Map' patchMapWithPatchingMoveNewElements :: PatchMapWithPatchingMove k p -> [PatchTarget p] -patchMapWithPatchingMoveNewElements = Map.elems . patchMapWithPatchingMoveNewElementsMap +patchMapWithPatchingMoveNewElements = toList . patchMapWithPatchingMoveNewElementsMap -- | Return a @'Map' k v@ with all the inserts/updates from the given @'PatchMapWithPatchingMove' k v@. patchMapWithPatchingMoveNewElementsMap :: PatchMapWithPatchingMove k p -> Map k (PatchTarget p) patchMapWithPatchingMoveNewElementsMap (PatchMapWithPatchingMove p) = Map.mapMaybe f p - where f ni = case _nodeInfo_from ni of - From_Insert v -> Just v - From_Move _ _ -> Nothing - From_Delete -> Nothing + where + f ni = case _nodeInfo_from ni of + From_Insert v -> Just v + From_Move _ _ -> Nothing + From_Delete -> Nothing -- | Create a 'PatchMapWithPatchingMove' that, if applied to the given 'Map', will sort -- its values using the given ordering function. The set keys of the 'Map' is @@ -223,62 +205,79 @@ patchMapWithPatchingMoveNewElementsMap (PatchMapWithPatchingMove p) = Map.mapMay patchThatSortsMapWith :: (Ord k, Monoid p) => (PatchTarget p -> PatchTarget p -> Ordering) - -> Map k (PatchTarget p) -> PatchMapWithPatchingMove k p + -> Map k (PatchTarget p) + -> PatchMapWithPatchingMove k p patchThatSortsMapWith cmp m = PatchMapWithPatchingMove $ Map.fromList $ catMaybes $ zipWith g unsorted sorted - where unsorted = Map.toList m - sorted = sortBy (cmp `on` snd) unsorted - f (to, _) (from, _) = if to == from then Nothing else + where + unsorted = Map.toList m + sorted = sortBy (cmp `on` snd) unsorted + f (to, _) (from, _) = + if to == from + then Nothing + else Just (from, to) - reverseMapping = Map.fromList $ catMaybes $ zipWith f unsorted sorted - g (to, _) (from, _) = if to == from then Nothing else + reverseMapping = Map.fromList $ catMaybes $ zipWith f unsorted sorted + g (to, _) (from, _) = + if to == from + then Nothing + else let movingTo = fromMaybe err $ Map.lookup from reverseMapping in Just (to, NodeInfo (From_Move from mempty) $ Just movingTo) - err = error "IMPOSSIBLE happens in patchThatSortsMapWith" + err = error "IMPOSSIBLE happens in patchThatSortsMapWith" -- | Create a 'PatchMapWithPatchingMove' that, if applied to the first 'Map' provided, -- will produce a 'Map' with the same values as the second 'Map' but with the -- values sorted with the given ordering function. patchThatChangesAndSortsMapWith - :: forall k p. (Ord k, Ord (PatchTarget p), Monoid p) + :: forall k p + . (Ord k, Ord (PatchTarget p), Monoid p) => (PatchTarget p -> PatchTarget p -> Ordering) - -> Map k (PatchTarget p) -> Map k (PatchTarget p) -> PatchMapWithPatchingMove k p + -> Map k (PatchTarget p) + -> Map k (PatchTarget p) + -> PatchMapWithPatchingMove k p patchThatChangesAndSortsMapWith cmp oldByIndex newByIndexUnsorted = patchThatChangesMap oldByIndex newByIndex - where newList = Map.toList newByIndexUnsorted - newByIndex = Map.fromList $ zip (fst <$> newList) $ sortBy cmp $ snd <$> newList + where + newList = Map.toList newByIndexUnsorted + newByIndex = Map.fromList $ zip (fst <$> newList) $ sortBy cmp $ snd <$> newList -- | Create a 'PatchMapWithPatchingMove' that, if applied to the first 'Map' provided, -- will produce the second 'Map'. -- Note: this will never produce a patch on a value. patchThatChangesMap :: forall k p - . (Ord k, Ord (PatchTarget p), Monoid p) + . (Ord k, Ord (PatchTarget p), Monoid p) => Map k (PatchTarget p) -> Map k (PatchTarget p) -> PatchMapWithPatchingMove k p patchThatChangesMap oldByIndex newByIndex = patch - where invert :: Map k (PatchTarget p) -> Map (PatchTarget p) (Set k) - invert = Map.fromListWith (<>) . fmap (\(k, v) -> (v, Set.singleton k)) . Map.toList - -- In the places where we use unionDistinct, a non-distinct key indicates a bug in this function - unionDistinct :: forall k' v'. Ord k' => Map k' v' -> Map k' v' -> Map k' v' - unionDistinct = Map.unionWith (error "patchThatChangesMap: non-distinct keys") - unionPairDistinct :: (Map k (From k v), Map k (To k)) -> (Map k (From k v), Map k (To k)) -> (Map k (From k v), Map k (To k)) - unionPairDistinct (oldFroms, oldTos) (newFroms, newTos) = (unionDistinct oldFroms newFroms, unionDistinct oldTos newTos) - -- Generate patch info for a single value - -- Keys that are found in both the old and new sets will not be patched - -- Keys that are found in only the old set will be moved to a new position if any are available; otherwise they will be deleted - -- Keys that are found in only the new set will be populated by moving an old key if any are available; otherwise they will be inserted - patchSingleValue :: PatchTarget p -> Set k -> Set k -> (Map k (From k p), Map k (To k)) - patchSingleValue v oldKeys newKeys = foldl' unionPairDistinct mempty $ align (toList $ oldKeys `Set.difference` newKeys) (toList $ newKeys `Set.difference` oldKeys) <&> \case + where + invert :: Map k (PatchTarget p) -> Map (PatchTarget p) (Set k) + invert = Map.fromListWith (<>) . fmap (\(k, v) -> (v, Set.singleton k)) . Map.toList + -- In the places where we use unionDistinct, a non-distinct key indicates a bug in this function + unionDistinct :: forall k' v'. Ord k' => Map k' v' -> Map k' v' -> Map k' v' + unionDistinct = Map.unionWith (error "patchThatChangesMap: non-distinct keys") + unionPairDistinct :: (Map k (From k v), Map k (To k)) -> (Map k (From k v), Map k (To k)) -> (Map k (From k v), Map k (To k)) + unionPairDistinct (oldFroms, oldTos) (newFroms, newTos) = (unionDistinct oldFroms newFroms, unionDistinct oldTos newTos) + -- Generate patch info for a single value + -- Keys that are found in both the old and new sets will not be patched + -- Keys that are found in only the old set will be moved to a new position if any are available; otherwise they will be deleted + -- Keys that are found in only the new set will be populated by moving an old key if any are available; otherwise they will be inserted + patchSingleValue :: PatchTarget p -> Set k -> Set k -> (Map k (From k p), Map k (To k)) + patchSingleValue v oldKeys newKeys = + foldl' unionPairDistinct mempty $ + align (toList $ oldKeys `Set.difference` newKeys) (toList $ newKeys `Set.difference` oldKeys) <&> \case This oldK -> (mempty, Map.singleton oldK Nothing) -- There's nowhere for this value to go, so we know we are deleting it That newK -> (Map.singleton newK $ From_Insert v, mempty) -- There's nowhere fo this value to come from, so we know we are inserting it These oldK newK -> (Map.singleton newK $ From_Move oldK mempty, Map.singleton oldK $ Just newK) - -- Run patchSingleValue on a These. Missing old or new sets are considered empty - patchSingleValueThese :: PatchTarget p -> These (Set k) (Set k) -> (Map k (From k p), Map k (To k)) - patchSingleValueThese v = \case - This oldKeys -> patchSingleValue v oldKeys mempty - That newKeys -> patchSingleValue v mempty newKeys - These oldKeys newKeys -> patchSingleValue v oldKeys newKeys - -- Generate froms and tos for all values, then merge them together - (froms, tos) = foldl' unionPairDistinct mempty $ Map.mapWithKey patchSingleValueThese $ align (invert oldByIndex) (invert newByIndex) - patch = unsafePatchMapWithPatchingMove $ align froms tos <&> \case + -- Run patchSingleValue on a These. Missing old or new sets are considered empty + patchSingleValueThese :: PatchTarget p -> These (Set k) (Set k) -> (Map k (From k p), Map k (To k)) + patchSingleValueThese v = \case + This oldKeys -> patchSingleValue v oldKeys mempty + That newKeys -> patchSingleValue v mempty newKeys + These oldKeys newKeys -> patchSingleValue v oldKeys newKeys + -- Generate froms and tos for all values, then merge them together + (froms, tos) = foldl' unionPairDistinct mempty $ Map.mapWithKey patchSingleValueThese $ align (invert oldByIndex) (invert newByIndex) + patch = + unsafePatchMapWithPatchingMove $ + align froms tos <&> \case This from -> NodeInfo from Nothing -- Since we don't have a 'to' record for this key, that must mean it isn't being moved anywhere, so it should be deleted. That to -> NodeInfo From_Delete to -- Since we don't have a 'from' record for this key, it must be getting deleted These from to -> NodeInfo from to @@ -291,15 +290,16 @@ patchThatChangesMap oldByIndex newByIndex = patch -- and where its old value should go to data NodeInfo k p = NodeInfo { _nodeInfo_from :: !(From k p) - -- ^ Where do we get the new value for this key? + -- ^ Where do we get the new value for this key? , _nodeInfo_to :: !(To k) - -- ^ If the old value is being kept (i.e. moved rather than deleted or - -- replaced), where is it going? + -- ^ If the old value is being kept (i.e. moved rather than deleted or + -- replaced), where is it going? } -deriving instance (Show k, Show p, Show (PatchTarget p)) => Show (NodeInfo k p) -deriving instance (Read k, Read p, Read (PatchTarget p)) => Read (NodeInfo k p) -deriving instance (Eq k, Eq p, Eq (PatchTarget p)) => Eq (NodeInfo k p) -deriving instance (Ord k, Ord p, Ord (PatchTarget p)) => Ord (NodeInfo k p) + +deriving stock instance (Show k, Show p, Show (PatchTarget p)) => Show (NodeInfo k p) +deriving stock instance (Read k, Read p, Read (PatchTarget p)) => Read (NodeInfo k p) +deriving stock instance (Eq k, Eq p, Eq (PatchTarget p)) => Eq (NodeInfo k p) +deriving stock instance (Ord k, Ord p, Ord (PatchTarget p)) => Ord (NodeInfo k p) -- | Traverse the 'NodeInfo' over the key, patch, and patch target. Because of -- the type families here, this doesn't it any bi- or tri-traversal class. @@ -308,26 +308,28 @@ bitraverseNodeInfo => (k0 -> f k1) -> (p0 -> f p1) -> (PatchTarget p0 -> f (PatchTarget p1)) - -> NodeInfo k0 p0 -> f (NodeInfo k1 p1) -bitraverseNodeInfo fk fp fpt (NodeInfo from to) = NodeInfo - <$> bitraverseFrom fk fp fpt from - <*> traverse fk to + -> NodeInfo k0 p0 + -> f (NodeInfo k1 p1) +bitraverseNodeInfo fk fp fpt (NodeInfo from to) = + NodeInfo + <$> bitraverseFrom fk fp fpt from + <*> traverse fk to -- | Change the 'From' value of a 'NodeInfo' nodeInfoMapFrom :: (From k v -> From k v) -> NodeInfo k v -> NodeInfo k v -nodeInfoMapFrom f ni = ni { _nodeInfo_from = f $ _nodeInfo_from ni } +nodeInfoMapFrom f ni = ni {_nodeInfo_from = f $ _nodeInfo_from ni} -- | Change the 'From' value of a 'NodeInfo', using a 'Functor' (or -- 'Applicative', 'Monad', etc.) action to get the new value nodeInfoMapMFrom :: Functor f => (From k v -> f (From k v)) -> NodeInfo k v -> f (NodeInfo k v) -nodeInfoMapMFrom f ni = fmap (\result -> ni { _nodeInfo_from = result }) $ f $ _nodeInfo_from ni +nodeInfoMapMFrom f ni = fmap (\result -> ni {_nodeInfo_from = result}) $ f $ _nodeInfo_from ni -- | Set the 'To' field of a 'NodeInfo' nodeInfoSetTo :: To k -> NodeInfo k v -> NodeInfo k v -nodeInfoSetTo to ni = ni { _nodeInfo_to = to } +nodeInfoSetTo to ni = ni {_nodeInfo_to = to} -- -- From @@ -335,14 +337,17 @@ nodeInfoSetTo to ni = ni { _nodeInfo_to = to } -- | Describe how a key's new value should be produced data From k p - = From_Insert (PatchTarget p) -- ^ Insert the given value here - | From_Delete -- ^ Delete the existing value, if any, from here - | From_Move !k !p -- ^ Move the value here from the given key, and apply the given patch - -deriving instance (Show k, Show p, Show (PatchTarget p)) => Show (From k p) -deriving instance (Read k, Read p, Read (PatchTarget p)) => Read (From k p) -deriving instance (Eq k, Eq p, Eq (PatchTarget p)) => Eq (From k p) -deriving instance (Ord k, Ord p, Ord (PatchTarget p)) => Ord (From k p) + = -- | Insert the given value here + From_Insert (PatchTarget p) + | -- | Delete the existing value, if any, from here + From_Delete + | -- | Move the value here from the given key, and apply the given patch + From_Move !k !p + +deriving stock instance (Show k, Show p, Show (PatchTarget p)) => Show (From k p) +deriving stock instance (Read k, Read p, Read (PatchTarget p)) => Read (From k p) +deriving stock instance (Eq k, Eq p, Eq (PatchTarget p)) => Eq (From k p) +deriving stock instance (Ord k, Ord p, Ord (PatchTarget p)) => Ord (From k p) -- | Traverse the 'From' over the key, patch, and patch target. Because of -- the type families here, this doesn't it any bi- or tri-traversal class. @@ -351,7 +356,8 @@ bitraverseFrom => (k0 -> f k1) -> (p0 -> f p1) -> (PatchTarget p0 -> f (PatchTarget p1)) - -> From k0 p0 -> f (From k1 p1) + -> From k0 p0 + -> f (From k1 p1) bitraverseFrom fk fp fpt = \case From_Insert pt -> From_Insert <$> fpt pt From_Delete -> pure From_Delete @@ -372,90 +378,95 @@ type To = Maybe -- | Helper data structure used for composing patches using the monoid instance. data Fixup k v - = Fixup_Delete - | Fixup_Update (These (From k v) (To k)) + = Fixup_Delete + | Fixup_Update (These (From k v) (To k)) -- | Compose patches having the same effect as applying the patches in turn: -- @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@ -instance ( Ord k -#if !MIN_VERSION_base(4,11,0) - , Semigroup p -#endif - , DecidablyEmpty p - , Patch p - ) => Semigroup (PatchMapWithPatchingMove k p) where +instance + ( Ord k + , DecidablyEmpty p + , Patch p + ) + => Semigroup (PatchMapWithPatchingMove k p) + where PatchMapWithPatchingMove mNew <> PatchMapWithPatchingMove mOld = PatchMapWithPatchingMove m where - connections = Map.elems $ Map.intersectionWithKey (\_ new old -> (_nodeInfo_to new, _nodeInfo_from old)) mNew mOld + connections = toList $ Map.intersectionWithKey (\_ new old -> (_nodeInfo_to new, _nodeInfo_from old)) mNew mOld h :: (Maybe k, From k p) -> [(k, Fixup k p)] h = \case (Just toAfter, From_Move fromBefore p) - | fromBefore == toAfter && isEmpty p - -> [ (toAfter, Fixup_Delete) - ] - | otherwise - -> [ (toAfter, Fixup_Update (This (From_Move fromBefore p))) - , (fromBefore, Fixup_Update (That (Just toAfter))) - ] + | fromBefore == toAfter && isEmpty p -> + [ (toAfter, Fixup_Delete) + ] + | otherwise -> + [ (toAfter, Fixup_Update (This (From_Move fromBefore p))) + , (fromBefore, Fixup_Update (That (Just toAfter))) + ] (Nothing, From_Move fromBefore _) -> [(fromBefore, Fixup_Update (That Nothing))] -- The item is destroyed in the second patch, so indicate that it is destroyed in the source map (Just toAfter, editBefore) -> [(toAfter, Fixup_Update (This editBefore))] (Nothing, _) -> [] mergeFixups Fixup_Delete Fixup_Delete = Fixup_Delete mergeFixups (Fixup_Update a) (Fixup_Update b) - | This x <- a, That y <- b - = Fixup_Update $ These x y - | That y <- a, This x <- b - = Fixup_Update $ These x y + | This x <- a + , That y <- b = + Fixup_Update $ These x y + | That y <- a + , This x <- b = + Fixup_Update $ These x y mergeFixups _ _ = error "PatchMapWithPatchingMove: incompatible fixups" - fixups = Map.fromListWithKey (\_ -> mergeFixups) $ concatMap h connections - combineNodeInfos niNew niOld = NodeInfo - { _nodeInfo_from = _nodeInfo_from niNew - , _nodeInfo_to = _nodeInfo_to niOld - } + fixups = Map.fromListWithKey (const mergeFixups) $ foldMap h connections + combineNodeInfos niNew niOld = + NodeInfo + { _nodeInfo_from = _nodeInfo_from niNew + , _nodeInfo_to = _nodeInfo_to niOld + } applyFixup ni = \case Fixup_Delete -> Nothing - Fixup_Update u -> Just $ NodeInfo - { _nodeInfo_from = case _nodeInfo_from ni of - -- The new patch has a Move, so it could be affected by the - -- corresponding From in the old patch. If that From exists, then - -- it is in the fixup here. - f@(From_Move _ p') -> case getHere u of - -- If there's no `From` fixup, just use the "new" `From` - Nothing -> f - -- If there's a `From` fixup which is an Insert, we can just apply - -- our patch to that and turn ourselves into an insert. - Just (From_Insert v) -> From_Insert $ applyAlways p' v - -- If there's a `From` fixup which is a Delete, then we can throw - -- our patch away because there's nothing to apply it to and - -- become a Delete ourselves. - Just From_Delete -> From_Delete - -- If there's a `From` fixup which is a Move, we need to apply - -- both the old patch and the new patch (in that order) to the - -- value, so we append the patches here. - Just (From_Move oldKey p) -> From_Move oldKey $ p' <> p - -- If the new patch has an Insert, it doesn't care what the fixup - -- value is, because it will overwrite it anyway. - f@(From_Insert _) -> f - -- If the new patch has an Delete, it doesn't care what the fixup - -- value is, because it will overwrite it anyway. - f@From_Delete -> f - , _nodeInfo_to = case _nodeInfo_to ni of - -- The old patch deletes this data, so we must delete it as well. - -- According to the code above, any time we have this situation we - -- should also have `getThere u == Nothing` because a fixup - -- shouldn't be generated. - Nothing -> Nothing - -- The old patch sends the value to oldToAfter - Just oldToAfter -> case getThere u of - -- If there is no fixup, that should mean that the new patch - -- doesn't do anything with the value in oldToAfter, so we still - -- send it to oldToAfter - Nothing -> Just oldToAfter - -- If there is a fixup, it should tell us where the new patch - -- sends the value at key oldToAfter. We send our value there. - Just mNewToAfter -> mNewToAfter - } - m = Map.differenceWithKey (\_ -> applyFixup) (Map.unionWith combineNodeInfos mNew mOld) fixups + Fixup_Update u -> + Just $ + NodeInfo + { _nodeInfo_from = case _nodeInfo_from ni of + -- The new patch has a Move, so it could be affected by the + -- corresponding From in the old patch. If that From exists, then + -- it is in the fixup here. + f@(From_Move _ p') -> case getHere u of + -- If there's no `From` fixup, just use the "new" `From` + Nothing -> f + -- If there's a `From` fixup which is an Insert, we can just apply + -- our patch to that and turn ourselves into an insert. + Just (From_Insert v) -> From_Insert $ applyAlways p' v + -- If there's a `From` fixup which is a Delete, then we can throw + -- our patch away because there's nothing to apply it to and + -- become a Delete ourselves. + Just From_Delete -> From_Delete + -- If there's a `From` fixup which is a Move, we need to apply + -- both the old patch and the new patch (in that order) to the + -- value, so we append the patches here. + Just (From_Move oldKey p) -> From_Move oldKey $ p' <> p + -- If the new patch has an Insert, it doesn't care what the fixup + -- value is, because it will overwrite it anyway. + f@(From_Insert _) -> f + -- If the new patch has an Delete, it doesn't care what the fixup + -- value is, because it will overwrite it anyway. + f@From_Delete -> f + , _nodeInfo_to = case _nodeInfo_to ni of + -- The old patch deletes this data, so we must delete it as well. + -- According to the code above, any time we have this situation we + -- should also have `getThere u == Nothing` because a fixup + -- shouldn't be generated. + Nothing -> Nothing + -- The old patch sends the value to oldToAfter + Just oldToAfter -> case getThere u of + -- If there is no fixup, that should mean that the new patch + -- doesn't do anything with the value in oldToAfter, so we still + -- send it to oldToAfter + Nothing -> Just oldToAfter + -- If there is a fixup, it should tell us where the new patch + -- sends the value at key oldToAfter. We send our value there. + Just mNewToAfter -> mNewToAfter + } + m = Map.differenceWithKey (const applyFixup) (Map.unionWith combineNodeInfos mNew mOld) fixups getHere :: These a b -> Maybe a getHere = \case This a -> Just a @@ -467,16 +478,17 @@ instance ( Ord k These _ b -> Just b That b -> Just b ---TODO: Figure out how to implement this in terms of PatchDMapWithPatchingMove rather than duplicating it here +-- TODO: Figure out how to implement this in terms of PatchDMapWithPatchingMove rather than duplicating it here + -- | Compose patches having the same effect as applying the patches in turn: -- @'applyAlways' (p <> q) == 'applyAlways' p . 'applyAlways' q@ -instance ( Ord k -#if !MIN_VERSION_base(4,11,0) - , Semigroup p -#endif - , DecidablyEmpty p - , Patch p - ) => Monoid (PatchMapWithPatchingMove k p) where +instance + ( Ord k + , DecidablyEmpty p + , Patch p + ) + => Monoid (PatchMapWithPatchingMove k p) + where mempty = PatchMapWithPatchingMove mempty mappend = (<>) diff --git a/src/Data/Patch/PatchOrReplacement.hs b/src/Data/Patch/PatchOrReplacement.hs index a61ddd0c..153f37ce 100644 --- a/src/Data/Patch/PatchOrReplacement.hs +++ b/src/Data/Patch/PatchOrReplacement.hs @@ -1,16 +1,8 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE StandaloneDeriving #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} -{-| -Description: A 'Patch' combinator type for patching or replacing with a separate new value. --} +-- | +-- Description: A 'Patch' combinator type for patching or replacing with a separate new value. module Data.Patch.PatchOrReplacement ( PatchOrReplacement (..) , _PatchOrReplacement_Patch @@ -19,12 +11,10 @@ module Data.Patch.PatchOrReplacement ) where import Control.Lens.TH (makePrisms) -import Data.Patch -#if !MIN_VERSION_base(4,11,0) -import Data.Semigroup (Semigroup (..)) -#endif import GHC.Generics +import Data.Patch + -- | Either a patch or a replacement value. -- -- A good patch type will describe small changes very efficiently, but @@ -37,19 +27,20 @@ import GHC.Generics data PatchOrReplacement p = PatchOrReplacement_Patch p | PatchOrReplacement_Replacement (PatchTarget p) - deriving (Generic) + deriving stock (Generic) -deriving instance (Eq p, Eq (PatchTarget p)) => Eq (PatchOrReplacement p) -deriving instance (Ord p, Ord (PatchTarget p)) => Ord (PatchOrReplacement p) -deriving instance (Show p, Show (PatchTarget p)) => Show (PatchOrReplacement p) -deriving instance (Read p, Read (PatchTarget p)) => Read (PatchOrReplacement p) +deriving stock instance (Eq p, Eq (PatchTarget p)) => Eq (PatchOrReplacement p) +deriving stock instance (Ord p, Ord (PatchTarget p)) => Ord (PatchOrReplacement p) +deriving stock instance (Show p, Show (PatchTarget p)) => Show (PatchOrReplacement p) +deriving stock instance (Read p, Read (PatchTarget p)) => Read (PatchOrReplacement p) -- | Traverse a 'PatchOrReplacement' with a function for each case traversePatchOrReplacement :: Functor f => (a -> f b) -> (PatchTarget a -> f (PatchTarget b)) - -> PatchOrReplacement a -> f (PatchOrReplacement b) + -> PatchOrReplacement a + -> f (PatchOrReplacement b) traversePatchOrReplacement f g = \case PatchOrReplacement_Patch p -> PatchOrReplacement_Patch <$> f p PatchOrReplacement_Replacement p -> PatchOrReplacement_Replacement <$> g p @@ -62,12 +53,12 @@ instance Patch p => Patch (PatchOrReplacement p) where PatchOrReplacement_Patch p -> apply p PatchOrReplacement_Replacement v -> \_ -> Just v -instance ( Monoid p -#if !MIN_VERSION_base(4,11,0) - , Semigroup p -#endif - , Patch p - ) => Monoid (PatchOrReplacement p) where +instance + ( Monoid p + , Patch p + ) + => Monoid (PatchOrReplacement p) + where mempty = PatchOrReplacement_Patch mempty mappend = (<>) diff --git a/src/Data/Semigroup/Additive.hs b/src/Data/Semigroup/Additive.hs index 1c4e44cc..11ee3df9 100644 --- a/src/Data/Semigroup/Additive.hs +++ b/src/Data/Semigroup/Additive.hs @@ -1,8 +1,5 @@ -{-# LANGUAGE ConstraintKinds #-} - -{-| -Description : A deprecated module containing a deprecated alias to the class for commutative semigroups --} +-- | +-- Description : A deprecated module containing a deprecated alias to the class for commutative semigroups module Data.Semigroup.Additive {-# DEPRECATED "Use 'Data.Semigroup.Commutative'" #-} ( Additive @@ -11,5 +8,6 @@ module Data.Semigroup.Additive import Data.Semigroup.Commutative {-# DEPRECATED Additive "Use 'Data.Semigroup.Commutative.Commutative'" #-} + -- | Deprecated alias for 'Commutative' type Additive = Commutative diff --git a/style.nix b/style.nix new file mode 100644 index 00000000..018e86de --- /dev/null +++ b/style.nix @@ -0,0 +1,61 @@ +{ system ? builtins.currentSystem +, inputs ? import ./inputs.nix { inherit system; } +, pkgs ? inputs.pkgs +}: + +let style = inputs."style.hs"; + + fourmolu = import (style + "/fourmolu.nix") { inherit system pkgs; }; + hlint = import (style + "/hlint.nix") { inherit system pkgs; }; + + styled = [ + "Setup.hs" + "src" + "test" + ]; + + # The styled code with patch.cabal beside it. fourmolu reads the + # extensions and the local modules from the cabal file. + source = pkgs.lib.fileset.toSource { + root = ./.; + fileset = pkgs.lib.fileset.unions (map (path: ./. + "/${path}") ([ "patch.cabal" ] ++ styled)); + }; + + check = name: tool: command: + pkgs.runCommand name { nativeBuildInputs = [ tool ]; } '' + cd ${source} + ${command} ${toString styled} + touch $out + ''; + + fourmolu-check = check "fourmolu-check" fourmolu "fourmolu --mode check --config ${fourmoluConfig}"; + hlint-check = check "hlint-check" hlint "hlint --with-group=generalise"; + + fourmoluAdditions = '' + fixities: + - infixl 1 & + - infixr 4 .~, %~ + - infixl 8 ^., ^.., ^? + ''; + + fourmoluConfig = pkgs.writeText "fourmolu.yaml" (builtins.readFile "${style}/fourmolu.yaml" + "\n" + fourmoluAdditions); + + syncConfig = source: target: '' + cmp -s ${source} "${target}" \ + || install -m 544 ${source} "${target}" + ''; + + # Keeps a copy of each shared style config next to the code, where the + # tools and editors look for it. The thunk's configs, with this repo's + # additions, are the source of truth: a copy that differs is overwritten. + syncConfigs = dir: '' + ${syncConfig fourmoluConfig "${dir}/fourmolu.yaml"} + ${syncConfig "${style}/hlint.yaml" "${dir}/.hlint.yaml"} + ''; +in { + inherit fourmolu hlint fourmolu-check hlint-check syncConfigs; + + checks = pkgs.linkFarmFromDrvs "style-checks" [ fourmolu-check hlint-check ]; + + shell = pkgs.mkShell { packages = [ fourmolu hlint ]; }; +} diff --git a/stylize b/stylize deleted file mode 100755 index 967146b1..00000000 --- a/stylize +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -for x in **/*.hs ; do stylish-haskell -i "$x" ; done diff --git a/test/hlint.hs b/test/hlint.hs index 7d39cab6..13dd3ec7 100644 --- a/test/hlint.hs +++ b/test/hlint.hs @@ -1,6 +1,7 @@ module Main where -import Control.Monad +import Data.Foldable (fold) +import Data.Traversable (for) import Language.Haskell.HLint (hlint) import System.Directory import System.Exit (exitFailure, exitSuccess) @@ -10,30 +11,32 @@ import System.FilePath.Find main :: IO () main = do pwd <- getCurrentDirectory - let runHlint f = hlint $ f: - [ "--ignore=Redundant do" - , "--ignore=Use camelCase" - , "--ignore=Redundant $" - , "--ignore=Use &&" - , "--ignore=Use &&&" - , "--ignore=Use const" - , "--ignore=Use >=>" - , "--ignore=Use ." - , "--ignore=Use unless" - , "--ignore=Reduce duplication" - , "--cpp-define=USE_TEMPLATE_HASKELL" - , "--ignore=Use tuple-section" - , "--ignore=Unused LANGUAGE pragma" -- hlint3 falsely believes that TypeOperators is not needed - ] - recurseInto = and <$> sequence - [ fileType ==? Directory - , fileName /=? ".git" - ] - matchFile = and <$> sequence - [ extension ==? ".hs" - ] - files <- find recurseInto matchFile (pwd "src") --TODO: Someday fix all hints in tests, etc. - ideas <- fmap concat $ forM files $ \f -> do - putStr $ "linting file " ++ drop (length pwd + 1) f ++ "... " + let runHlint f = + hlint $ + f + : [ "--ignore=Redundant do" + , "--ignore=Use camelCase" + , "--ignore=Redundant $" + , "--ignore=Use &&" + , "--ignore=Use &&&" + , "--ignore=Use const" + , "--ignore=Use >=>" + , "--ignore=Use ." + , "--ignore=Use unless" + , "--ignore=Reduce duplication" + , "--cpp-define=USE_TEMPLATE_HASKELL" + , "--ignore=Use tuple-section" + , "--ignore=Unused LANGUAGE pragma" -- hlint3 falsely believes that TypeOperators is not needed + ] + recurseInto = + and + <$> sequence + [ fileType ==? Directory + , fileName /=? ".git" + ] + matchFile = extension ==? ".hs" + files <- find recurseInto matchFile (pwd "src") -- TODO: Someday fix all hints in tests, etc. + ideas <- fmap fold $ for files $ \f -> do + putStr $ "linting file " <> drop (length pwd + 1) f <> "... " runHlint f if null ideas then exitSuccess else exitFailure diff --git a/test/tests.hs b/test/tests.hs index fd061c38..60291db8 100644 --- a/test/tests.hs +++ b/test/tests.hs @@ -1,59 +1,58 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE TemplateHaskell #-} + module Main where -import Test.HUnit (runTestTT, (~:), assertEqual, errors, failures, test) -import Data.Patch ( Patch(apply) ) -import Data.Patch.MapWithMove ( patchThatChangesMap ) -import Data.Patch.MapWithPatchingMove (PatchMapWithPatchingMove) -import qualified Data.Patch.MapWithPatchingMove as PatchMapWithPatchingMove -import Data.Map as Map ( Map, fromList, singleton ) -import Hedgehog (checkParallel, discover, Property, property, forAll, PropertyT, (===)) -import Hedgehog.Gen as Gen ( int ) -import Hedgehog.Range as Range ( linear ) -import Control.Monad (replicateM) -import System.Exit (exitFailure, exitSuccess) -import Data.Sequence as Seq ( foldMapWithIndex, replicateM ) +import Data.Map as Map (Map, fromList, singleton) import Data.Semigroup ( Sum (..) -#if !MIN_VERSION_base(4,11,0) - , Semigroup(..) -#endif ) +import Data.Sequence as Seq (foldMapWithIndex, replicateM) +import Hedgehog (Property, PropertyT, checkParallel, discover, forAll, property, (===)) +import Hedgehog.Gen as Gen (int) +import Hedgehog.Range as Range (linear) +import System.Exit (exitFailure, exitSuccess) +import Test.HUnit (assertEqual, errors, failures, runTestTT, test, (~:)) + +import Data.Patch (Patch (apply)) +import Data.Patch.MapWithMove (patchThatChangesMap) +import Data.Patch.MapWithPatchingMove (PatchMapWithPatchingMove) +import Data.Patch.MapWithPatchingMove qualified as PatchMapWithPatchingMove main :: IO () main = do - counts <- runTestTT $ test - [ "Simple Move" ~: do - let mapBefore = Map.fromList [(0,1)] - mapAfter = Map.fromList [(0,0),(1,1)] - patch = patchThatChangesMap mapBefore mapAfter - afterPatch = apply patch mapBefore - assertEqual "Patch creates the same Map" (Just mapAfter) afterPatch - , "Property Checks" ~: propertyChecks - , "Insert and Patch" ~: do - let i :: PatchMapWithPatchingMove () (Sum Int) - i = PatchMapWithPatchingMove.insertMapKey () 1 - p = PatchMapWithPatchingMove.patchMapKey () (Sum 2) - pAfterI = PatchMapWithPatchingMove.insertMapKey () 3 - assertEqual "Insert after patch is the same as insert" (i <> p) i - assertEqual "Patch after insert is a patched insert" (p <> i) pAfterI - ] - if errors counts + failures counts == 0 then exitSuccess else exitFailure + counts <- + runTestTT $ + test + [ "Simple Move" ~: do + let mapBefore = Map.fromList [(0, 1)] + mapAfter = Map.fromList [(0, 0), (1, 1)] + patch = patchThatChangesMap mapBefore mapAfter + afterPatch = apply patch mapBefore + assertEqual "Patch creates the same Map" (Just mapAfter) afterPatch + , "Property Checks" ~: propertyChecks + , "Insert and Patch" ~: do + let i :: PatchMapWithPatchingMove () (Sum Int) + i = PatchMapWithPatchingMove.insertMapKey () 1 + p = PatchMapWithPatchingMove.patchMapKey () (Sum 2) + pAfterI = PatchMapWithPatchingMove.insertMapKey () 3 + assertEqual "Insert after patch is the same as insert" (i <> p) i + assertEqual "Patch after insert is a patched insert" (p <> i) pAfterI + ] + if errors counts + failures counts == 0 then exitSuccess else exitFailure propertyChecks :: IO Bool -propertyChecks = checkParallel $$(discover) +propertyChecks = checkParallel $$discover prop_patchThatChangesMap :: Property prop_patchThatChangesMap = property $ do - mapBefore <- makeRandomIntMap - mapAfter <- makeRandomIntMap - let patch = patchThatChangesMap mapBefore mapAfter - Just mapAfter === apply patch mapBefore + mapBefore <- makeRandomIntMap + mapAfter <- makeRandomIntMap + let patch = patchThatChangesMap mapBefore mapAfter + Just mapAfter === apply patch mapBefore makeRandomIntMap :: Monad m => PropertyT m (Map Int Int) makeRandomIntMap = do - let genNum = Gen.int (Range.linear 0 100) - length <- forAll genNum - listOfNumbers <- forAll $ Seq.replicateM length genNum - pure $ Seq.foldMapWithIndex Map.singleton listOfNumbers + let genNum = Gen.int (Range.linear 0 100) + len <- forAll genNum + listOfNumbers <- forAll $ Seq.replicateM len genNum + pure $ Seq.foldMapWithIndex Map.singleton listOfNumbers