Невозможно понять раздел «Различные базы данных» в документе стека - PullRequest
2 голосов
/ 28 апреля 2020

Я читаю документ стека из https://docs.haskellstack.org/en/stable/GUIDE/

В разделе Разные базы данных говорится, что

Базы данных в стеке являются многоуровневыми. Например, список баз данных, который мы только что дали, называется локальной базой данных. Это слой поверх базы данных снимков, которая содержит библиотеки и исполняемые файлы, указанные в самом снимке. Наконец, GH C сам поставляется с рядом библиотек и исполняемых файлов, которые образуют глобальную базу данных. Чтобы быстро понять это, мы можем посмотреть на вывод команды stack exe c - gh c -pkg list в нашем проекте helloworld:

/home/michael/.stack/programs/x86_64-linux/ghc-7.10.2/lib/ghc-7.10.2/package.conf.d
   Cabal-1.22.4.0
   array-0.5.1.0
   base-4.8.1.0
   bin-package-db-0.0.0.0
   binary-0.7.5.0
   bytestring-0.10.6.0
   containers-0.5.6.2
   deepseq-1.4.1.1
   directory-1.2.2.0
   filepath-1.4.0.0
   ghc-7.10.2
   ghc-prim-0.4.0.0
   haskeline-0.7.2.1
   hoopl-3.10.0.2
   hpc-0.6.0.2
   integer-gmp-1.0.0.0
   pretty-1.1.2.0
   process-1.2.3.0
   rts-1.0
   template-haskell-2.10.0.0
   terminfo-0.4.0.1
   time-1.5.0.1
   transformers-0.4.2.0
   unix-2.7.1.0
   xhtml-3000.2.1
/home/michael/.stack/snapshots/x86_64-linux/nightly-2015-08-26/7.10.2/pkgdb
   stm-2.4.4
/home/michael/helloworld/.stack-work/install/x86_64-linux/nightly-2015-08-26/7.10.2/pkgdb
   acme-missiles-0.3
   helloworld-0.1.0.0

Я проделал тот же эксперимент с windows, но результаты отличаются:

  1. Создайте новый проект с помощью stack new helloworld

  2. Редактировать helloworld/src/Lib.hs следующим образом

      module Lib
          ( someFunc
          ) where
    
      import Acme.Missiles
    
      someFunc :: IO ()
      someFunc = launchMissiles
    
  3. Редактировать helloworld/package.yaml следующим образом

    dependencies:
    - base >= 4.7 && < 5
    - text
    - filepath
    - containers
    - acme-missiles
    
  4. Поскольку acme-missiles не будет в LTS, поэтому я добавляю extra-deps: в helloworld/stack.yaml

    extra-deps:
    - acme-missiles-0.3 # not in the LTS
    
  5. stack build и успех, войдите как

    E:\work-category-theory\helloworld>stack build
    Stack has not been tested with GHC versions above 8.6, and using 8.8.3, this may fail
    Stack has not been tested with Cabal versions above 2.4, but version 3.0.1.0 was found, this may fail
    acme-missiles> configure
    acme-missiles> Configuring acme-missiles-0.3...
    acme-missiles> build
    acme-missiles> Preprocessing library for acme-missiles-0.3..
    acme-missiles> Building library for acme-missiles-0.3..
    acme-missiles> [1 of 2] Compiling Acme.Missiles
    acme-missiles> [2 of 2] Compiling Acme.Missiles.STM
    acme-missiles> copy/register
    acme-missiles> Installing library in C:\sr\snapshots\c1955c78\lib\x86_64-windows-ghc-8.8.3\acme-missiles-0.3-5Q3zlWTjrQa
    Fyz88eRyQT2
    acme-missiles> Registering library for acme-missiles-0.3..
    Building all executables for `helloworld' once. After a successful build of all of them, only specified executables will
     be rebuilt.
    helloworld   > configure (lib + exe)
    Configuring helloworld-0.1.0.0...
    helloworld   > build (lib + exe)
    Preprocessing library for helloworld-0.1.0.0..
    Building library for helloworld-0.1.0.0..
    [1 of 2] Compiling Lib
    [2 of 2] Compiling Paths_helloworld
    Preprocessing executable 'helloworld-exe' for helloworld-0.1.0.0..
    Building executable 'helloworld-exe' for helloworld-0.1.0.0..
    [1 of 2] Compiling Main
    [2 of 2] Compiling Paths_helloworld
    Linking .stack-work\dist\29cc6475\build\helloworld-exe\helloworld-exe.exe ...
    helloworld   > copy/register
    Installing library in E:\work-category-theory\helloworld\.stack-work\install\5056a8ea\lib\x86_64-windows-ghc-8.8.3\hello
    world-0.1.0.0-BBUUJBmDe2RHSTnItHQtB0
    Installing executable helloworld-exe in E:\work-category-theory\helloworld\.stack-work\install\5056a8ea\bin
    Registering library for helloworld-0.1.0.0..
    Completed 2 action(s).
    
  6. Теперь позвоните stack exec -- ghc-pkg list

    E:\work-category-theory\helloworld>stack exec -- ghc-pkg list
    Stack has not been tested with GHC versions above 8.6, and using 8.8.3, this may fail
    Stack has not been tested with Cabal versions above 2.4, but version 3.0.1.0 was found, this may fail
    C:\Users\Chansey\AppData\Local\Programs\stack\x86_64-windows\ghc-8.8.3\lib\package.conf.d
        Cabal-3.0.1.0
        Win32-2.6.1.0
        array-0.5.4.0
        base-4.13.0.0
        binary-0.8.7.0
        bytestring-0.10.10.0
        containers-0.6.2.1
        deepseq-1.4.4.0
        directory-1.3.6.0
        filepath-1.4.2.1
        (ghc-8.8.3)
        ghc-boot-8.8.3
        ghc-boot-th-8.8.3
        ghc-compact-0.1.0.0
        ghc-heap-8.8.3
        ghc-prim-0.5.3
        ghci-8.8.3
        haskeline-0.7.5.0
        hpc-0.6.0.3
        integer-gmp-1.0.2.0
        libiserv-8.8.3
        mtl-2.2.2
        parsec-3.1.14.0
        pretty-1.1.3.6
        process-1.6.8.0
        rts-1.0
        stm-2.5.0.0
        template-haskell-2.15.0.0
        text-1.2.4.0
        time-1.9.3
        transformers-0.5.6.2
        xhtml-3000.2.2.1
    
    C:\sr\snapshots\c1955c78\pkgdb
        acme-missiles-0.3
    
    E:\work-category-theory\helloworld\.stack-work\install\5056a8ea\pkgdb
        helloworld-0.1.0.0
    

Вы видите, что мои выводы отличаются от документа.

Вопрос:

Почему acme-missiles-0.3 находится в C:/sr/snapshots/, а не /helloworld/.stack-work? (Обратите внимание, что в windows, C:/sr/ эквивалентно ~/.stack)

Кроме того, в FAQ по документу от https://docs.haskellstack.org/en/stable/faq/ упоминается, что

Где установлен стек и будет ли он мешать gh c (et c), который я уже установил?

Сам стек установлен в обычных местах системы в зависимости от используемого вами механизма (см. страницу «Установка и обновление»). Stack устанавливает библиотеки Stackage в ~ / .stack и любые библиотеки проектов или дополнительные зависимости в каталоге .stack-work в каталоге каждого проекта. Ничто из этого не должно влиять на любые существующие инструменты Haskell.

acme-missiles-0.3 - это дополнительные зависимости, почему в моем эксперименте он находится в каталоге ~/.stack, а не .stack-work в каталоге проекта?

Спасибо.

...